question

B14D3-8285 avatar image
0 Votes"
B14D3-8285 asked B14D3-8285 commented

How to add computer name in Get-LocalGroupMember -Group "Administrators"

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

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

NewbieJones-6218 avatar image
0 Votes"
NewbieJones-6218 answered B14D3-8285 commented

Second option.

 $comp=$env:computername
 Get-LocalGroupMember -Group "Administrators" | Select-Object ObjectClass, Name, @{name="ComputerName";expression={$comp}} | Export-CSV filename.csv
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Perfect! i will go for this one, Thanks alot

0 Votes 0 ·
NewbieJones-6218 avatar image
0 Votes"
NewbieJones-6218 answered B14D3-8285 commented

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
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

This is good per machine

0 Votes 0 ·