Ran in to the "Failed to compare two elements" known error with Get-LocalGroupMember this morning. Needed to find a way around this, but required a bit of old school command line. The code below obviously applies to Hyper-V clusters and nodes. Modify to your liking, but should get you most of the way there.
https://github.com/PowerShell/PowerShell/issues/2996
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| Get-Cluster -Name hvc* -Domain "your domain" | Where Name -NotMatch "regex" | Get-ClusterNode | %{
Invoke-Command -ComputerName $_.Name -ScriptBlock {
$members = net localgroup Administrators |
Where-Object {$_ -AND $_ -notmatch "Command Completed Successfully"} |
Select-Object -Skip 4 |
Select-String "your domain or some other filter"
[PSCustomObject]@{
Computername = $env:COMPUTERNAME
Group = "Administrators"
Members=$members
}
} -AsJob
};While(Get-Job -State Running){}; $results = Get-Job | Receive-Job; Get-Job | Remove-Job
$results| select -Property * -ExcludeProperty RunspaceId, PSComputerName | ft
|
No comments:
Post a Comment