functions/remote/Search-DomainUser.ps1
function Search-DomainUser { [CmdletBinding()] param ( [Parameter(ValueFromPipeline = $true)] [PSFComputer[]] $ComputerName, [string] $OU, [string] $Filter = '*', [string] $Server, [pscredential] $Credential ) begin { $adParameters = $PSBoundParameters | ConvertTo-PSFHashtable -Include Server, Credential $targets = [System.Collections.ArrayList]::new() if ($OU) { $parameters = $PSBoundParameters | ConvertTo-PSFHashtable -Include OU, Filter, Server, Credential foreach ($computer in Resolve-Computer @parameters) { $null = $targets.Add($computer) } } } process { foreach ($computer in $ComputerName) { $null = $targets.Add($computer) } } end { $localAdmins = Get-AdminPrincipal -ComputerName $targets -AsHashtable $serviceAccounts = Get-ServiceAccount -ComputerName $targets -AsHashtable $taskAccounts = Get-TaskAccount -ComputerName $targets -AsHashtable $computerNames = $localAdmins.Keys, $serviceAccounts.Keys, $taskAccounts.Keys | Sort-Object -Unique foreach ($computer in $computerNames) { $param = @{ ComputerName = $computer LocalAdmins = $localAdmins[$computer] ServiceAccounts = $serviceAccounts[$computer] TaskAccounts = $taskAccounts[$computer] DomainOnly = $true } New-ComputerUserReport @param @adParameters } } } |