The Stop-Computer cmdlet has the -ComputerName switch, through which you can specify a list of systems that require shutdown. If the DeathStar service doesn't exist, you'll get an error. You may be familiar with the Restart-Computer cmdlet in PowerShell.Restart-Computer is a common command a lot of IT professionals use to reboot the local as well as many remote computers. Step 3: Shutdown Remote Computers Using PowerShell cmdlet. ![]() For more information typeĮXAMPLE 1 Restart-RemoteService -Name DeathStar -ComputerName Yavin Add one line to the batch file that reads: for /f 'tokens1' a in (PCNames.txt) do shutdown /m a /r /f. The name of the computer where the service lives. Create a text file (lets say 'PCNames.txt') with a list of computer names. You'll get an error if you attempt to restart a non-existent service. This command restarts the Server01 remote computer and then waits up to 5 minutes (300 seconds) for Windows PowerShell to be available on the restarted computer before it continues. This function does all this unnecessary work for you. Restart a remote computer and wait: PS C:\> Restart-Computer -ComputerName 'Server01' -Wait -For PowerShell -Timeout 300 -Delay 2. Get-Service -Name DeathStar -ComputerName Yavin |įorEach-Object # or (and no, you can't pipe the service directly to `Restart-Service`) You have to use Get-Service to get the remote service: $service = Get-Service -Name DeathStar -ComputerName Yavin You can use the cmdlet to restart your own computer without much hassle: PS C:> Restart-Computer. In Windows 7 or 8, hit Start, and then type 'powershell. One of the annoying features of PowerShell is that the Stop-Service, Start-Service and Restart-Service cmdlets don't have ComputerName parameters to start/stop/restart a service on a remote computer. In Windows 10, press Windows+X and then choose PowerShell (Admin) from the Power User menu.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |