Private/ConvertTo-OIMUID.ps1
|
function ConvertTo-OIMUID { <# .SYNOPSIS Resolves a UID string from either a raw UID string or an OIM object. .DESCRIPTION Membership/CRUD convenience functions accept either a UID string or an object returned by a Get-OIM* function (e.g. Get-OIMPerson). This extracts the UID value either way, so callers don't have to do it themselves. .PARAMETER InputObject A UID string, or an object with a property named by -PropertyName. .PARAMETER PropertyName The property to read the UID from when -InputObject isn't already a string. .EXAMPLE ConvertTo-OIMUID -InputObject $person -PropertyName UID_Person .EXAMPLE ConvertTo-OIMUID -InputObject 'QER-A31C...' -PropertyName UID_Person .OUTPUTS System.String #> [CmdletBinding()] [OutputType('System.String')] param( [Parameter(Mandatory = $true, Position = 0)] $InputObject, [Parameter(Mandatory = $true, Position = 1)] [string]$PropertyName ) if ($InputObject -is [string]) { return $InputObject } if ($null -ne $InputObject.$PropertyName) { return $InputObject.$PropertyName } throw "Could not resolve '$PropertyName' from the supplied object. Pass a UID string, or an object with a '$PropertyName' property." } |