Reputation: 353
I am trying to retrieve the list of Administrators from a system. Below is the script that I am using currently to retrieve from the local system.
Get-LocalGroupMember -Group Administrators
This retrieves the result as expected. Now to retrieve the same result from a remote system, I explored invoke-command
option and its able to connect to the remote system. The issue is I am unable to retrieve the details from older system which has powershell version older than 5.1 since Get-LocalGroupMember
cmdlet is available only from 5.1. Kindly help to get the local administrator group details from a remote system which has PS version older than 5.1
Below is my current script.
$AdminAccountName=Invoke-Command -ComputerName $server -ScriptBlock { Get-LocalGroupMember -Group Administrators| where {$_.name -eq 'Domain\accountName'}|Select name}
Upvotes: 0
Views: 1082
Reputation: 938
For Powershell versions before 5.1 - you need to use net.exe command:
net localgroup Administrators
It will need some parsing, but the command is there.
This also works with Invoke-Command:
Invoke-Command ComputerName -ScriptBlock { net localgroup administrators }
Upvotes: 1