Everyone has heard of PowerShell. If you haven’t crawl out of that cave you have been living in, and start using PowerShell to administer your networked computers.
For years now, PowerShell has been successfully used to remotely administer and monitor computers, both in a domain environment, as well as standalone, workgrouped computers. Using this powerful scripting solution can give you back many hours per month of administration time, allowing you to concentrate on other projects. Heck, you might even be able to get a raise by using PowerShell to create new efficiencies.
This list is by no means comprehensive. This is a just a short list of cmdlets you should know if you want get started in remote administration with PowerShell. Feel free to make contributions to this list, or suggestions for aadditions.
Enter-PSSession
Example
Enter-PSSession -ComputerName RemoteComputerName -Credential UserNameWithRights
Explanation
This is the PowerSHell equivalent of SSH in Linux. By using this handing command, you can connect to a remote machine and execute commands, as if you were sitting directly at the machine.
Invoke-Command
Example
Invoke-Command -Computer RemoteComputerName -ScriptBlock { CommandToRun }
Explanation
When you don’t need to execute multiple commands on a remote computer, you can use Invoke-Command to run a single command on the remote machine. You can also execute PowerShell scripts, DOS commands, etc., that reside on or are accessible by the remote computer.
Restart-Computer
Example
Restart-Computer -ComputerName RemoteComputerName -Force
Explanation
This is a really powerful and dangerous command. WIth Restart-Computer, you can do just as it says, restart a remote computer. You can also restart groups of computers by specifying a list or array containing the names of the computers to be restarted.
Stop-Computer
Example
Stop-Computer -ComputerName RemoteComputerName -Force
Explanation
A companion to the Restart-Computer cmdlet, this command performs a shutdown of the target mcahine(s). Handy for shutting down groups of machines for, eg, hardware upgrades, or maybe some sort of emergency at a remote site.
Test-Connection
Example
Test-Connection -ComputerName ComputerToPing -Source ComputerToPingFrom
Explanation
Test-Connection is equivalent to the DOS PING command. It allows you to check to see if the path is open between the computer you are logged in to, or by using the -Source switch, you can test between remote machines.
Add-Computer
Example
Add-Computer -ComputerName Computer(s)ToBeJoined -DomainName MyDomain.com -Credential DomainName\UserName -Restart
Explanation
Adding a computer to a domain is no mystery, but with PowerShell, you can actually perform this task remotely. Simply give Add-Computer a name or list of names, the domain name, and your credentials, and bang! you’re off to the races!
Get-EventLog
Example
Get-Eventlog -LogName system -Newest 1000 -ComputerName RemoteComputerName
Explanation
The Get-EventLog cmdlet is handy for get items from any of the Windows Event logs that an administrator has access to, both on the local machine as well as remote machines. You don’t have to dump the whole log, though. The cmdlet has built functionality to filter based on Username, InstanceID, Source, Entry Type, and more. Further, you can have it only show you the newest items, or items between specific dates.
Get-Process
Example
Get-Process -ComputerName TargetComputer *word*
Explanation
Used by itself, Get-Process will list all currently running processes on the local or a remote machine. If the list is a bit, daunting, you can easily filter it by included a string to filter on. In the example, the cmdlet is searching on the computer named TargetComputer for all instances containing the string “word”.
Stop-Process
Example
Stop-Process -Name "notepad"
Explanation
Stop-Process does exactly that: Stop the specified process. One thing to know is that it only works with the local machine. However, you can us Invoke-Command to execute the command on a remote computer.