Advertisement
Guest User

Untitled

a guest
Jan 25th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. function Write-Log
  2. {
  3. param([Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)][AllowEmptyString()][string]$Message)
  4. Write-Verbose -Verbose ("[{0:s}] {1}`r`n" -f (get-date), $Message)
  5. }
  6.  
  7.  
  8. $destHost="10.9.13.21"
  9. $user = "administrator"
  10. $pass = ConvertTo-SecureString -String "PASSWORD" -AsPlainText -Force
  11. $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $user, $pass
  12.  
  13.  
  14. #net start WinRM
  15.  
  16. if ((Get-Service -Name winrm).Status -ne "Running")
  17. { winrm quickconfig }
  18.  
  19. $list = (get-item wsman:\localhost\Client\TrustedHosts).value
  20.  
  21. if (!($list.contains("$destHost")))
  22. { write-log "Item not in trusted list"; Set-Item wsman:\localhost\Client\TrustedHosts $destHost -Concatenate -Force }
  23.  
  24. Enter-PSSession -ComputerName $destHost -credential $cred
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement