Sep 10 2020 07:11 AM
Hi Team,
Is there a way to get a list of servers that user or a group has access?
I am looking for a script that would give me list of servers in which that particular user or group is added to Server Local Administrators.
Thanks
Yash
Sep 11 2020 12:04 AM
Hi @yashsedani,
You will need to do following for the script works correctly:
1. Create a Servers.txt file which has your servers list.
2. Run the script.
3. Choose type (group or user).
4. Enter your credentials (All servers must be authorized for these credentials).
If user or group belongs to domain, the results will be cyan.
If user or group belongs to local server, the results will be green.
$Domain = $env:userdomain
$Servers = Get-Content C:\Servers.txt
$Selection = Read-Host "Select Group or user (for group=g for user=u)"
if ($Selection -eq "u")
{ $Credential = Get-Credential
$Username = Read-Host "Enter User Name"
Foreach ($Server in $Servers)
{
$Group = Invoke-Command -ScriptBlock {(Get-LocalGroupMember "Administrators").Name} -ComputerName $Server -ErrorAction SilentlyContinue
If ($Group -contains "$Server\$Username")
{
Write-host "$Server" -ForegroundColor Green
}
ElseIf ($Group -contains "$Domain\$Username")
{
Write-host "$Server" -ForegroundColor Cyan
}
}
}
Elseif ($Selection -eq "g")
{
$Credential = Get-Credential
$Groupname = Read-Host "Enter Group Name"
Foreach ($Server in $Servers)
{
$Group = Invoke-Command -ScriptBlock {(Get-LocalGroupMember "Administrators").Name} -ComputerName $Server -ErrorAction SilentlyContinue
If ($Group -contains "$Server\$Groupname")
{
Write-host "$Server" -ForegroundColor Green
}
ElseIf ($Group -contains "$Domain\$Groupname")
{
Write-host "$Server" -ForegroundColor Cyan
}
}
}
else
{
Write-host "Wrong parameter! Exiting..." -ForegroundColor Red
}
Greetings
Hasan Emre SATILMIŞ