I am trying to add the computer name in the output of Get-LocalGroupMember -Group "Administrators".
Can someone help me how to add the computer name in the output of this script.
TIA
I am trying to add the computer name in the output of Get-LocalGroupMember -Group "Administrators".
Can someone help me how to add the computer name in the output of this script.
TIA
Second option.
$comp=$env:computername
Get-LocalGroupMember -Group "Administrators" | Select-Object ObjectClass, Name, @{name="ComputerName";expression={$comp}} | Export-CSV filename.csv
You can get the computername using $env:computername
Not sure exactly how you want this output, but you could use this to name the file.
For example...
$comp=$env:computername
$logfile= ("$comp.csv")
Get-LocalGroupMember -Group "Administrators" | Select-Object ObjectClass, Name | Export-CSV $logfile
20 people are following this question.