Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement