Skip to main content

PowerShell get local admins on remote PCs


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:
Linux Android App cheat sheet:
https://play.google.com/store/apps/details?id=com.LinuxMobileKit


Click on links below to find out more:

https://play.google.com/store/apps/details?id=soulrefresh.beautiful.prayer

Catholic Rosary Guide  for Android:

https://play.google.com/store/apps/details?id=com.myrosaryapp

http://quickbytesstuff.blogspot.sg/2014/09/how-to-recite-rosary.html

Divine Mercy Chaplet Guide (A Powerful prayer):

https://play.google.com/store/apps/details?id=com.dmercyapp

Comments

Popular posts from this blog

Copy a single file using robocopy

Copy a single file using robocopy from a local folder to a shared folder on the network.
A simple rule of thumb before any disaster strike, don't interchange the source and the destination.

If source and destination is mistakenly reverse, files might get overwritten. To avoid any loss of data do a test with a dummy file to ensure things work perfectly.
Robocopy [source][destination]   [file to be copied]
robocopy c:\local_c_folder  \\PC_network\shared_folder   file_to_be_copied_xx.txt
The command will be completed successfully provided the network access right has no issues.

Robocopy works quite good on large files. A simple copy or xcopy command will also work but the speed might vary.

Robocopy is free it can be accessed from command line. No need to install the resource kit tool if the operating system is Windows 7 or newer version.

Copy files with selected file extension using PowerShell and Robocopy:

$extension = ('.pdf', '.jpg', '.txt')
gci d:\WorkFolde…

WMIC get computer name

WMIC get computer model, manufacturer, computer name and  username.
WMIC is a command-line tool and that can generate information about computer model, its manufacturer, its username and other informations depending on the parameters provided.
Why would you need a command line tool if there’s a GUI to check?
If you have 20 or 100 computers, or even more. It’s quite a big task just checking the GUI to check the computer model and username.
If you have remote computers, you need to delegate someone in the remote office or location to check.
Or you can just write a batch file or script to automate the task.
Here’s the code below on how get computer model, manufacturer and the username.
Open an elevated command prompt and type:
wmic computersystem get "Model","Manufacturer", "Name", "UserName"
Just copy and paste the code above, the word “computersystem” does not need to be change to a computer name.
A sample output below will be generated if the co…