Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 258290

PowerCLI/PowerShell script to retrieve local admins on Windows servers

$
0
0

Hello, I hope I'm not too cheeky to ask the question here... I'm trying to retrieve the local admins group members of all Windows VM servers and export them to a csv. I wrote this code but it only exports to csv one server. So the loop is not correctly set, however I'm new to this -scriptblock feature and I don't know how to append all VMs data:

 

$winVMS = Get-VM  | ?{$_.Guest.GuestFamily -like "win*" -and $_.PowerState -eq "PoweredOn"  }
$Credential = Get-Credential

ForEach($vm in $winVMS){


    $Computer = $vm + "<domainName>"    Invoke-Command -ComputerName $Computer -Credential $Credential -ScriptBlock {         Get-LocalGroupMember -Group "Administrators"             } | Export-Csv -Path 'C:\Users\xxxxxx\Desktop\localAdmins.csv' -NoTypeInformation
}  

Viewing all articles
Browse latest Browse all 258290

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>