Created
May 30, 2021 10:41
-
-
Save mastersign/6dd77e5530ec60c18c87cbf2be69a14c to your computer and use it in GitHub Desktop.
Restart Windows Service on Remote Host
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| param ( | |
| $Host, | |
| $User = "Administrator", | |
| $Service | |
| ) | |
| $driveName = "tmpRemoteConnDrive" | |
| $cred = Get-Credential -Credential "$Host\$User" | |
| New-PSDrive -Name $driveName -PSProvider FileSystem -Root "\\$Host\c`$" -Credential $cred | |
| Get-Service -ComputerName $Host $Service | Restart-Service | |
| Remove-PSDrive $driveName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment