ListLocalGroupMembership.ps1
$computerName = Read-Host 'Enter computer name or press <Enter> for localhost'
if ($computerName -eq "") {$computerName = "$env:computername"}
$computer = [ADSI]"WinNT://$computerName,computer"
$groups = $computer.psbase.Children | Where-object { $_.psbase.schemaclassname -eq 'group' }
foreach ($group in $groups)
{
$users = $group.psbase.invoke("Members")
$group.name
write-host "----------------------------------------------------"
if ($users -ne $null)
{
foreach ($user in $users)
{
$user.GetType().InvokeMember("Name","GetProperty",$null,$user,$null)
}
}
else
{
write-host "-----EMPTY-----" -foreground "red"
}
write-host "----------------------------------------------------"
write-host ""
}
The basis of this script was taken from here.
You could easily take this a stage further and log this data to a repository and then alert any changes made.
thanks for the script! tip for others: you can also do $user.GetType().InvokeMember("adspath","GetProperty",$null,$user,$null) to get the domain part of the username
ReplyDelete