Getting local admins from all PCs
Hello,
I am new to power shell scripting and i got a task where i need to restive all the users that have local admins on their devices.
Any help?
I managed to create a script but i got errors on all users.
This is the script:
#Get Current Computer Name
$computer = $env:computername
#Get Current UserName
$CurrentUser = whoami
#Get User’s Local Group Membership
$CurrentUserGroups = whoami /groups
#Check if current user is a member of the Local Admins group
$CurrentUserAdmin = $CurrentUserGroups -like “*S-1-5-32-544*”
#If user is an admin
if ($CurrentUserAdmin) {
$body = ConvertTo-JSON @{Device = $computer; User = $CurrentUser; IsAdmin = ‘true’}
#Start Flow
Invoke-RestMethod -uri $URI -Method Post -body $body -ContentType ‘application/json’
}
#If user is not an admin
else {
$body = ConvertTo-JSON @{Device = $computer; User = $CurrentUser; IsAdmin = ‘false’}
#Start Flow
Invoke-RestMethod -uri $URI -Method Post -body $body -ContentType ‘application/json’
}
Hello, I am new to power shell scripting and i got a task where i need to restive all the users that have local admins on their devices.Any help? I managed to create a script but i got errors on all users.This is the script:#Get Current Computer Name$computer = $env:computername#Get Current UserName$CurrentUser = whoami#Get User’s Local Group Membership$CurrentUserGroups = whoami /groups#Check if current user is a member of the Local Admins group$CurrentUserAdmin = $CurrentUserGroups -like “*S-1-5-32-544*”#If user is an adminif ($CurrentUserAdmin) {$body = ConvertTo-JSON @{Device = $computer; User = $CurrentUser; IsAdmin = ‘true’}#Start FlowInvoke-RestMethod -uri $URI -Method Post -body $body -ContentType ‘application/json’}#If user is not an adminelse {$body = ConvertTo-JSON @{Device = $computer; User = $CurrentUser; IsAdmin = ‘false’}#Start FlowInvoke-RestMethod -uri $URI -Method Post -body $body -ContentType ‘application/json’} Read More