Last active
August 29, 2015 14:03
-
-
Save jschell/a13459151dd40111ff6b to your computer and use it in GitHub Desktop.
Functions to make WinRM on azure run smoother
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 connect-azurePSSession | |
| { | |
| <# | |
| borrowed from : http://jrich523.wordpress.com/2010/07/21/update-creating-a-profile-for-a-remote-session/ | |
| #> | |
| [cmdletBinding()] | |
| Param( | |
| [Parameter(Mandatory=$True)] | |
| [string]$hostName, | |
| [Parameter(Mandatory=$True)] | |
| [int]$portNumber, | |
| [Parameter(Mandatory=$True)] | |
| [PSCredential]$credentials, | |
| [Parameter(Mandatory=$False)] | |
| [string]$sessionName | |
| ) | |
| $newSessionOptions = @{ | |
| computerName = "$hostName" | |
| port = "$portNumber" | |
| authentication = "Negotiate" | |
| credential = $credentials | |
| useSSL = $true | |
| sessionOption = (New-PSSessionOption -SkipCACheck -SkipCNCheck) | |
| } | |
| if($sessionName) | |
| { $newSessionOptions += @{ name = $sessionName} } | |
| $session = new-psSession @newSessionOptions | |
| invoke-command -session $session -scriptBlock { | |
| ## Begin Remote Profile ## | |
| function Prompt | |
| { | |
| #Put the ID of the command in, so we can get/invoke-history easier | |
| #eg: "r 4" will re-run the command that has [4]: in the prompt | |
| $nextCommandId = (Get-History -count 1).Id + 1 | |
| #Output prompt string | |
| #Notice: no angle brackets, makes it easy to paste my buffer to the web | |
| Write-Host -ForegroundColor Yellow -NoNewLine "`n$env:computername." | |
| Write-Host -ForegroundColor Gray -NoNewLine "$env:userdnsdomain" | |
| Write-Host -ForegroundColor 03 "`n[$(Get-Location)]" | |
| #Break up second prompt line to change color of history counter | |
| Write-Host -ForegroundColor Yellow -NoNewLine "PS: [" | |
| Write-Host -ForegroundColor Gray -NoNewLine "${nextCommandId}" | |
| Write-Host -ForegroundColor Yellow -NoNewLine "] `n" | |
| return " " | |
| } | |
| } | |
| enter-psSession $session | |
| } # end connect-azurePSSession |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment