Skip to content

Instantly share code, notes, and snippets.

@ploegert
Created January 25, 2016 15:45
Show Gist options
  • Select an option

  • Save ploegert/d4c2352251f92a4d1320 to your computer and use it in GitHub Desktop.

Select an option

Save ploegert/d4c2352251f92a4d1320 to your computer and use it in GitHub Desktop.
Connect to remote host
function Write-Log
{
param([Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)][AllowEmptyString()][string]$Message)
Write-Verbose -Verbose ("[{0:s}] {1}`r`n" -f (get-date), $Message)
}
$destHost="10.9.13.21"
$user = "administrator"
$pass = ConvertTo-SecureString -String "PASSWORD" -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $user, $pass
#net start WinRM
if ((Get-Service -Name winrm).Status -ne "Running")
{ winrm quickconfig }
$list = (get-item wsman:\localhost\Client\TrustedHosts).value
if (!($list.contains("$destHost")))
{ write-log "Item not in trusted list"; Set-Item wsman:\localhost\Client\TrustedHosts $destHost -Concatenate -Force }
Enter-PSSession -ComputerName $destHost -credential $cred
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment