How to list members of local administrators on a domain environment?
How to get localgroup administrator members on remote computers in an active directory domain?
Below is a piece of code using Powershell to list members of local administrator groups on remote PCs.
Code should be run in an elevated mode which has proper access on remote computers.
It needs also WMI to be enable on remote computers being queried. Which is quite dangerous to enable all the time, after using WMI then it is good to disable the settings in order not to be exploited by other users, viruses or malwares.
If WMI is not enable on the remote PC then PowerShell will throw this error:
Connecting to remote server SERVER_NAME failed with the following error message : WinRM cannot complete the operation. Verify that the specified computer name is valid, that the computer is accessible over the network, and that a firewall exception for the WinRM service is
enabled and allows access from this computer. By default, the WinRM firewall exception for public profiles limits access to remote computers within the same local subnet.
Code below reads computers.txt file on drive d. Computers.txt has list of computer names that will be queried by PowerShell and if the script is successful it will write a text file with the remote computer name as its file name and the content will be the local admin members.
Change the script path accordingly where the computers.txt is readable.
Code snippet:
================
$computers = Get-content "D:\computers.txt"
ForEach ($Line In $computers)
{
#write-host $Line
Invoke-command -ComputerName $line -ScriptBlock { net localgroup administrators} | out-file d:\$line.txt
}
================
Cheers.. Hope it helps..
==================
Free Android Apps:
Click on links below to find out more:
https://play.google.com/store/apps/details?id=soulrefresh.beautiful.prayer
Catholic Rosary Guide for Android:
Pray the Rosary every day, countless blessings will be showered upon your life if you recite the Rosary faithfully.
https://play.google.com/store/apps/details?id=com.myrosaryapp
https://play.google.com/store/apps/details?id=com.myrosaryapp
http://quickbytesstuff.blogspot.sg/2014/09/how-to-recite-rosary.html
Comments
Post a Comment