Skip to content

Instantly share code, notes, and snippets.

@ChabaOk

ChabaOk/addtrustedhost.ps1

Last active Dec 23, 2016
Embed
What would you like to do?
Add winrm trusted host
Start-Service WinRM
$myTrustWinRM = get-Item WSMan:\localhost\Client\TrustedHosts
if($myTrustWinRM.Value.Length -eq 0)
{
$myNewTrust = "192.168.1.113"
Write-Host "new trustedhosts"
}
else
{
$myTargetServerIP = "192.168.1.113"
$myNewTrust = ($myTrustWinRM).Value + ", $myTargetServerIP"
Write-Host "append trustedhosts"
}
Set-Item WSMan:\localhost\Client\TrustedHosts -Value $myNewTrust
$MyCred = Get-Credential "administrator"
$nanoPSHost = New-PSSession -ComputerName $myNewTrust -Credential $MyCred
Enter-PSSession -Id ($nanoPSHost).id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.