We are trying to standardize our local Administrators group on all our PC’s. I know I can do this through GPO but first I want to find the computers without the specific set of groups so we know if we need to tweak things a bit.
I found this Script which will list the local groups but I am unsure how to have it sift through and check the groups like I want.
$computername = "Test01"
$Group = "Administrators"
Try {
If ([ADSI]::Exists("WinNT://$($ComputerName)/$($Group),group")) {
([ADSI]"WinNT://$($ComputerName)/$($Group),group").Members() | ForEach-Object {
$PathElements = ($_.GetType().InvokeMember("AdsPath", 'GetProperty', $null, $_, $null)).Split('/',[StringSplitOptions]::RemoveEmptyEntries)
If ($PathElements[-2] -eq 'WinNT:') {
$PathElements[-1]
} Else {
"$($PathElements[-2])\$($PathElements[-1])"
}
}
} Else {
"Group '$($Group)' not found on $($ComputerName)!" | Write-Error
}
} Catch {
$_.Exception.Message | Write-Error
}
I would want to check it against a list like: Domain Admins, Psych Local Admins, etc. I would also need to run this script remotely from my PC and not on each individual PC (we do not have PSRemoting on).
Thanks,
Scott