Skip to content

Instantly share code, notes, and snippets.

@johnjohnsp1
Forked from pcgeek86/azrdp.ps1
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save johnjohnsp1/910a508c4eb296da4b06 to your computer and use it in GitHub Desktop.

Select an option

Save johnjohnsp1/910a508c4eb296da4b06 to your computer and use it in GitHub Desktop.
function azrdp {
<#
.Author
Trevor Sullivan <[email protected]>
.Description
Invoke a RDP session to an Azure Virtual Machine, without having to type the
Cloud Service name or Virtual Machine name.
.Outputs
None
.Links
http://trevorsullivan.net
http://twitter.com/pcgeek86
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $false)]
[switch] $PromptSubscription
)
try {
if ($PromptSubscription) {
$Subscription = Get-AzureSubscription | Select-Object -Property SubscriptionName,SubscriptionId | Out-GridView -PassThru;
if (!$Subscription) {
Write-Warning -Message 'No Azure subscription was selected.';
return;
}
Select-AzureSubscription -SubscriptionName $Subscription.SubscriptionName;
}
$VM = Get-AzureVM -ErrorAction Stop | Out-GridView -PassThru;
if (!$VM) {
Write-Warning -Message 'No virtual machine was selected.';
return;
}
Get-AzureRemoteDesktopFile -ServiceName $VM.ServiceName -Name $VM.Name -Launch;
}
catch [System.ArgumentException] {
if ($PSItem.Exception.Message -match 'Add-AzureAccount') {
Add-AzureAccount;
& $PSCmdlet.MyInvocation.MyCommand.Name @PSBoundParameters;
}
}
}
azrdp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment