ps/Modules/Alkami.DevOps.Operations/Private/Get-ADUserProfileList.ps1

58 lines
1.8 KiB
PowerShell
Raw Normal View History

2023-05-30 22:51:22 -07:00
function Get-ADUserProfileList {
<#
.SYNOPSIS
Retrieves an array of CIM instance user profiles on the target server that are in either the CORP or FH domains.
.SYNOPSIS
Retrieves an array of CIM instance user profiles on the target server that are in either the CORP or FH domains.
.PARAMETER ComputerName
The name of the server where the operation should be performed. If omitted, defaults to the current host.
.PARAMETER Domains
Array of domains to process. If omitted, defaults to both CORP and FH.
.OUTPUTS
An array of CIM instance user profile objects.
#>
[CmdLetBinding()]
[OutputType([object[]])]
param(
[Parameter(Mandatory = $false)]
[string] $ComputerName = $null,
[Parameter(Mandatory = $false)]
[ValidateSet('CORP', 'FH')]
[string[]] $Domains = @('CORP', 'FH')
)
$logLead = (Get-LogLeadName)
$result = @()
# Test if we can get CIM Instances; abort if not.
if ($null -eq (Get-Command Get-CimInstance -ErrorAction SilentlyContinue)) {
Write-Warning "$logLead : Can't CimInstance on this host; aborting."
return $result
}
# Determine if we are executing remotely.
$splatParams = @{}
if ( -not (Test-StringIsNullOrWhitespace -Value $ComputerName) -and -not (Compare-StringToLocalMachineIdentifiers -stringToCheck $ComputerName )) {
$splatParams['ComputerName'] = "$ComputerName"
}
$workingList = Get-CimInstance -ClassName Win32_UserProfile @splatParams
foreach ( $domain in $Domains ) {
$interim = $workingList | Where-Object { $_.SID.StartsWith($_DomainSidPrefix[$domain]) }
if ( -not (Test-IsCollectionNullOrEmpty -Collection $interim )) {
Write-Verbose "$logLead : Found $($interim.Length) entries for $domain domain."
$result += $interim
}
}
return $result
}