Created
January 25, 2016 15:45
-
-
Save ploegert/d4c2352251f92a4d1320 to your computer and use it in GitHub Desktop.
Connect to 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
| 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