Skip to content

Instantly share code, notes, and snippets.

@mastersign
Created May 30, 2021 10:41
Show Gist options
  • Select an option

  • Save mastersign/6dd77e5530ec60c18c87cbf2be69a14c to your computer and use it in GitHub Desktop.

Select an option

Save mastersign/6dd77e5530ec60c18c87cbf2be69a14c to your computer and use it in GitHub Desktop.
Restart Windows Service on Remote Host
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