Created
May 8, 2012 14:58
-
-
Save zachbonham/2635955 to your computer and use it in GitHub Desktop.
Required Bootstrapping of WinRM before its of any value for PowerShell Remoting
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
param($computername=$(throw "-computername is required"), $username=$(throw "-username is required"), $password=$(throw "-password is required")) | |
<# | |
.SYNOPSIS | |
Bootstraps a server for use with WinRM. | |
Requires running under a username which is an adminstrator on remote machine. | |
Requires PSEXEC from sysinternals | |
.PARAMETER $computername | |
The name of the remote computer we are bootstrapping. This should take the form of '\\wddcsdmon01'. | |
.PARAMETER $username | |
The domain\account we are using to authenticate against the remote server. | |
.PARAMETER $password | |
$username password. This is *clear* text for now. | |
.DESCRIPTION | |
Bootstraps a server for use with WinRM. | |
Requires running under a username which is an adminstrator on remote machine. | |
Requires PSEXEC from sysinternals | |
.EXAMPLE | |
.\bootstrap_server -computername | |
#> | |
import-module .\remote.ps1 | |
function invoke($description, [scriptblock]$scriptblock) | |
{ | |
write-host "$computername invoking $description" | |
$output = invoke-remoteexpression -computer $computername -expression $scriptblock -noprofile -username $username -password $password | out-string | |
write-debug $output | |
write-host "$computername $description COMPLETE" | |
} | |
$psexec_command = get-command psexec -erroraction silentlycontinue | |
if ( $psexec_command -eq $null ) | |
{ | |
write-error "PSExec not found in path. Please make sure PSExec is in your PATH environment variable." | |
return | |
} | |
write-host "bootstrapping $computername for WinRM" | |
write-host "PSExec found at $($psexec_command.definition)" | |
invoke "set-executionpolicy Unrestricted -force" { set-executionpolicy Unrestricted -force } | |
invoke "winrm quickconfig -quiet" { winrm quickconfig -quiet } | |
invoke "enable-wsmancredssp -role server -force" { enable-wsmancredssp -role server -force } | |
invoke "winrm set winrm/config/client '@{TrustedHosts=""*""}'" { winrm set winrm/config/client '@{TrustedHosts="*"}' } | |
write-host "$computername WinRM bootstrap COMPLETE" | |
write-host "" | |
write-host "example of testing WinRM remoting:" | |
write-host "" | |
write-host 'c:\>$cred = get-credential' | |
write-host 'c:\>invoke-command -computername wddcsdwmsa293.mkappsdev.com -scriptblock { dir c:\temp } -credential $cred -authentication credssp' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment