Hi,
Im after a script that interrogates all end user machines on our domain, and shows a list of all users who are in the local admin group and on what machine.
Is this poss?
Hi,
Im after a script that interrogates all end user machines on our domain, and shows a list of all users who are in the local admin group and on what machine.
Is this poss?
It would be great if you can make you question bit more clear.
Are you facing any issue with an existing script or are you expecting a ready made script ?
Would it be something as simple as this?
[pre]
$computers = get-adcomputer -filter * | select -expand name
invoke-command -computername $computers -scriptblock {Get-LocalGroupMember -Group administrators}
[/pre]
Also the report im after is to show all users who are in local admin group which also exports results to a CSV or excel file for example.
I have tried this but couldnt get it to work
https://gallery.technet.microsoft.com/scriptcenter/Get-remote-machine-members-bc5faa57
Probably a lot more complicated than it needs to be, but here is one I wrote:
function Get-LocalAdmin { param ($ComputerName) $localAdmins = @() $regex_user = 'Win32_UserAccount \(Domain \= "(.+)", Name = "(.+)"\)' $regex_group = 'Win32_Group \(Domain \= "(.+)", Name = "(.+)"\)' $admins = Get-CimInstance -ClassName win32_groupuser -ComputerName $ComputerName | Where-Object GroupComponent -like "*Administrators*" $admins.PartComponent | ForEach-Object { if ($_ -like "Win32_UserAccount*") { $_ | Select-String -Pattern $regex_user | ForEach-Object { $localAdmins += [PSCustomObject]@{ Type = "User" Value = "$($_.Matches.Groups[1].Value)\$($_.Matches.Groups[2].Value)" } } } elseif ($_ -like "Win32_Group*") { $_ | Select-String -Pattern $regex_group | ForEach-Object { $localAdmins += [PSCustomObject]@{ Type = "Group" Value = "$($_.Matches.Groups[1].Value)\$($_.Matches.Groups[2].Value)" } } } else { $_ | Select-String -Pattern $regex_group | ForEach-Object { $localAdmins += [PSCustomObject]@{ Type = "Other" Value = "$($_.Matches.Groups[1].Value)\$($_.Matches.Groups[2].Value)" } } } } }
You could get that into a CSV by piping the output to Export-Csv:
Get-LocalAdmin server01 | Export-Csv -NoTypeInformation e:\temp\localadmin.csv
Hi Charles,
Tried running what you suggested but i get
PS C:\WINDOWS\system32> C:\Temp\123.ps1
At C:\Temp\123.ps1:2 char:1
Yeah, looks like I missed the final curly brace when I pasted it into the post. I updated it, but it was just adding a ‘}’ to the very end of the code (line 47).
[quote quote=187654]Yeah, looks like I missed the final curly brace when I pasted it into the post. I updated it, but it was just adding a ‘}’ to the very end of the code (line 47).
[/quote]
Thanks again Charles!. Im new to some PS scripting so forgive my pestering… so i pasted in the updated script and ran through PS ISE but when i hit run script it just goes back to PS C:\WINDOWS\system32> C:\Temp.…
Now im guessing i need to enter our corp domain, and some other bit of info for the script to pickup what i need, but where do i enter it?