functions/remote/Get-ServiceAccount.ps1
function Get-ServiceAccount { [CmdletBinding()] param ( [switch] $AsHashtable, [Parameter(ValueFromPipeline = $true)] [PSFComputer[]] $ComputerName, [string] $OU, [string] $Filter = '*', [string] $Server, [pscredential] $Credential ) begin { $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) } } $scriptblock = [scriptblock]::Create((Get-Command Get-LocalServiceAccount).Definition) } process { foreach ($computer in $ComputerName) { $null = $targets.Add($computer) } } end { $results = Invoke-PSFCommand -ComputerName $targets -ScriptBlock $scriptblock if (-not $AsHashtable) { return $results } $hash = @{} foreach ($resultGroup in $results | Group-Object ComputerName) { $hash[$resultGroup.Name] = $resultGroup.Group } $hash } } |