Skip to content

Instantly share code, notes, and snippets.

@MattHodge
Created May 30, 2015 00:57
Show Gist options
  • Save MattHodge/217eab7fa1056365bc6a to your computer and use it in GitHub Desktop.
Save MattHodge/217eab7fa1056365bc6a to your computer and use it in GitHub Desktop.
# Ensure the build fails if there is a problem.
# The build will fail if there are any errors on the remote machine too!
$ErrorActionPreference = 'Stop'
# Create a PSCredential Object using the "User" and "Password" parameters that you passed to the job
$SecurePassword = $env:Password | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $env:User, $SecurePassword
# Invoke a command on the remote machine.
# It depends on the type of job you are executing on the remote machine as to if you want to use "-ErrorAction Stop" on your Invoke-Command.
Invoke-Command -ComputerName $env:Computer -Credential $cred -ScriptBlock {
# Restart the W32Time service
Restart-Service -Name W32Time
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment