Create a text file named servers.txt and put all servers in the file (one server at one line)
Copy and paste the below code (in Blue) in a text file and save it as LocalAdmins.Ps1. Put both Servers.txt and LocalAdmins.PS1 at the same location and execute the Script from Powershell console as .\LocalAdmins.Ps1
#Read Server Names from the list Servers.txt
Get-Content "Servers.txt" |foreach-object {
$Content = $_
# Loop only executed when ping is successful
if (test-connection -computername $Content -count 1 -quiet)
{
#Fetching details from servers
([ADSI]"WinNT://$_/Administrators").Members() | Select-Object `
@{n='Computername';e={ $Content }},
@{n='User/Group Name';e={ $_.GetType().InvokeMember('Name', 'GetProperty', $Null, $_, $Null) }},
@{n='ADSPath';e={ $_.GetType().InvokeMember('ADSPath', 'GetProperty', $Null, $_, $Null) }},
@{n='Type';e={ $_.GetType().InvokeMember('class', 'GetProperty', $Null, $_, $Null) }}
}}| export-csv Local_Admins.csv –notypeinformation
Wait for the script to finis and a CSV file will be ready once it is done.
Copy and paste the below code (in Blue) in a text file and save it as LocalAdmins.Ps1. Put both Servers.txt and LocalAdmins.PS1 at the same location and execute the Script from Powershell console as .\LocalAdmins.Ps1
#Read Server Names from the list Servers.txt
Get-Content "Servers.txt" |foreach-object {
$Content = $_
# Loop only executed when ping is successful
if (test-connection -computername $Content -count 1 -quiet)
{
#Fetching details from servers
([ADSI]"WinNT://$_/Administrators").Members() | Select-Object `
@{n='Computername';e={ $Content }},
@{n='User/Group Name';e={ $_.GetType().InvokeMember('Name', 'GetProperty', $Null, $_, $Null) }},
@{n='ADSPath';e={ $_.GetType().InvokeMember('ADSPath', 'GetProperty', $Null, $_, $Null) }},
@{n='Type';e={ $_.GetType().InvokeMember('class', 'GetProperty', $Null, $_, $Null) }}
}}| export-csv Local_Admins.csv –notypeinformation
Wait for the script to finis and a CSV file will be ready once it is done.