Skip to content

Instantly share code, notes, and snippets.

@mkurdej
Last active September 18, 2015 14:49
Show Gist options
  • Save mkurdej/e5e25f25f65339969ef2 to your computer and use it in GitHub Desktop.
Save mkurdej/e5e25f25f65339969ef2 to your computer and use it in GitHub Desktop.
Azure: Add SSH endpoint to a VM
$ErrorActionPreference = "Stop"
Add-AzureAccount
Select-AzureSubscription -Name "Continuous Integration"
Write-Host 'The following VM instances are available:'
$vms = Get-AzureVM
$vms | foreach { $_.Name }
$vmName = Read-Host 'Enter the name of the VM to show its endpoints'
$vm = $vms | where { $_.Name -eq $vmName }
Write-Host 'The following endpoints are set:'
$eps = Get-AzureEndpoint -VM $vm
function Read-Host-Default {
param($default, $prompt)
$prompt = Read-Host "$prompt [or press enter to accept the default: $($default)]"
$prompt = ($default,$prompt)[[bool]$prompt]
return $prompt
}
$eps | Sort-Object -Property Name | Format-Table Name, LocalPort, Port, Protocol, Vip
$ep_name = Read-Host-Default "SSH" 'Enter endpoint name'
$protocol = Read-Host-Default "tcp" 'Enter protocol (tcp|udp)'
$public_port = Read-Host-Default 2222 'Enter public port'
$local_port = Read-Host-Default 22 'Enter local port'
Add-AzureEndpoint -VM $vm -Name $ep_name -Protocol $protocol -PublicPort $public_port -LocalPort $local_port | Update-AzureVM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment