23
23
24
24
namespace Microsoft . Azure . Commands . Compute
25
25
{
26
+ using Microsoft . Azure . Management . Network . Models ;
27
+
26
28
[ Cmdlet ( VerbsCommon . Get , ProfileNouns . RemoteDesktopFile ) ]
27
29
public class GetAzureRemoteDesktopFileCommand : VirtualMachineRemoteDesktopBaseCmdlet
28
30
{
31
+ const string PublicIPAddressResource = "publicIPAddresses" ;
32
+ const string NetworkInterfaceResouce = "networkInterfaces" ;
33
+ const string LoadBalancerResouce = "loadBalancers" ;
34
+
29
35
[ Parameter (
30
36
Mandatory = true ,
31
37
Position = 0 ,
@@ -39,40 +45,88 @@ public class GetAzureRemoteDesktopFileCommand : VirtualMachineRemoteDesktopBaseC
39
45
Mandatory = true ,
40
46
Position = 1 ,
41
47
ValueFromPipelineByPropertyName = true ,
42
- HelpMessage = "The resource name." ) ]
48
+ HelpMessage = "The resource name." ,
49
+ ParameterSetName = "StandAloneVMDownload" ) ]
50
+ [ Parameter (
51
+ Mandatory = true ,
52
+ Position = 1 ,
53
+ ValueFromPipelineByPropertyName = true ,
54
+ HelpMessage = "The resource name." ,
55
+ ParameterSetName = "StandAloneVMLaunch" ) ]
43
56
[ ValidateNotNullOrEmpty ]
44
57
public string Name { get ; set ; }
45
58
59
+ [ Parameter (
60
+ Mandatory = true ,
61
+ Position = 1 ,
62
+ ValueFromPipelineByPropertyName = true ,
63
+ HelpMessage = "The instance of the VM in virtual machine scaleset." ,
64
+ ParameterSetName = "ScaleSetVMDownload" ) ]
65
+ [ Parameter (
66
+ Mandatory = true ,
67
+ Position = 1 ,
68
+ ValueFromPipelineByPropertyName = true ,
69
+ HelpMessage = "The instance of the VM in virtual machine scaleset." ,
70
+ ParameterSetName = "ScaleSetVMLaunch" ) ]
71
+ [ ValidateNotNullOrEmpty ]
72
+ public string InstanceId { get ; set ; }
73
+
46
74
[ Parameter (
47
75
Mandatory = true ,
48
76
Position = 2 ,
49
77
ValueFromPipelineByPropertyName = true ,
50
78
HelpMessage = "Path and name of the output RDP file." ,
51
- ParameterSetName = "Download " ) ]
79
+ ParameterSetName = "StandAloneVMDownload " ) ]
52
80
[ Parameter (
53
81
Mandatory = false ,
54
82
Position = 2 ,
55
83
ValueFromPipelineByPropertyName = true ,
56
84
HelpMessage = "Path and name of the output RDP file." ,
57
- ParameterSetName = "Launch" ) ]
85
+ ParameterSetName = "StandAloneVMLaunch" ) ]
86
+ [ Parameter (
87
+ Mandatory = true ,
88
+ Position = 2 ,
89
+ ValueFromPipelineByPropertyName = true ,
90
+ HelpMessage = "Path and name of the output RDP file." ,
91
+ ParameterSetName = "ScaleSetVMDownload" ) ]
92
+ [ Parameter (
93
+ Mandatory = false ,
94
+ Position = 2 ,
95
+ ValueFromPipelineByPropertyName = true ,
96
+ HelpMessage = "Path and name of the output RDP file." ,
97
+ ParameterSetName = "ScaleSetVMLaunch" ) ]
58
98
[ ValidateNotNullOrEmpty ]
59
99
public string LocalPath { get ; set ; }
60
100
61
101
[ Parameter (
62
102
Mandatory = true ,
63
103
Position = 3 ,
64
- HelpMessage = "Start a remote desktop session to the specified role instance." ,
65
- ParameterSetName = "Launch" ) ]
104
+ HelpMessage = "Start a remote desktop session to the specified role instance." ,
105
+ ParameterSetName = "StandAloneVMLaunch" ) ]
106
+ [ Parameter (
107
+ Mandatory = true ,
108
+ Position = 3 ,
109
+ HelpMessage = "Start a remote desktop session to the specified role instance." ,
110
+ ParameterSetName = "ScaleSetVMLaunch" ) ]
66
111
public SwitchParameter Launch
67
112
{
68
113
get ;
69
114
set ;
70
115
}
71
116
72
- const string PublicIPAddressResource = "publicIPAddresses" ;
73
- const string NetworkInterfaceResouce = "networkInterfaces" ;
74
- const string LoadBalancerResouce = "loadBalancers" ;
75
-
117
+ [ Parameter (
118
+ Mandatory = true ,
119
+ ValueFromPipelineByPropertyName = true ,
120
+ HelpMessage = "The virtual machine scaleset name." ,
121
+ ParameterSetName = "ScaleSetVMDownload" ) ]
122
+ [ Parameter (
123
+ Mandatory = true ,
124
+ ValueFromPipelineByPropertyName = true ,
125
+ HelpMessage = "The virtual machine scaleset name." ,
126
+ ParameterSetName = "ScaleSetVMLaunch" ) ]
127
+ [ ValidateNotNullOrEmpty ]
128
+ public string VirtualMachineScaleSetName { get ; set ; }
129
+
76
130
public override void ExecuteCmdlet ( )
77
131
{
78
132
base . ExecuteCmdlet ( ) ;
@@ -86,17 +140,41 @@ public override void ExecuteCmdlet()
86
140
string address = string . Empty ;
87
141
int port = defaultPort ;
88
142
89
- // Get Azure VM
90
- var vmResponse = this . VirtualMachineClient . Get ( this . ResourceGroupName , this . Name ) ;
143
+ NetworkInterface nic ;
144
+
145
+ if ( this . ParameterSetName . Contains ( "StandAloneVM" ) )
146
+ {
147
+ // Get standalone Azure VM
148
+ var vmResponse = this . VirtualMachineClient . Get ( this . ResourceGroupName , this . Name ) ;
91
149
92
- var nicId = vmResponse . VirtualMachine . NetworkProfile . NetworkInterfaces . First ( ) . ReferenceUri ;
150
+ var nicId = vmResponse . VirtualMachine . NetworkProfile . NetworkInterfaces . First ( ) . ReferenceUri ;
93
151
94
- // Get the NIC
95
- var nicResourceGroupName = this . GetResourceGroupName ( nicId ) ;
152
+ // Get the NIC
153
+ var nicResourceGroupName = this . GetResourceGroupName ( nicId ) ;
96
154
97
- var nicName = this . GetResourceName ( nicId , NetworkInterfaceResouce ) ;
155
+ var nicName = this . GetResourceName ( nicId , NetworkInterfaceResouce ) ;
98
156
99
- var nic = this . NetworkClient . NetworkManagementClient . NetworkInterfaces . Get ( nicResourceGroupName , nicName ) ;
157
+ nic = this . NetworkClient . NetworkManagementClient . NetworkInterfaces . Get (
158
+ nicResourceGroupName ,
159
+ nicName ) ;
160
+ }
161
+ else
162
+ {
163
+ var vmResponse = this . VirtualMachineScaleSetVMClient . Get ( this . ResourceGroupName , this . VirtualMachineScaleSetName , this . InstanceId ) ;
164
+
165
+ var nicId = vmResponse . VirtualMachineScaleSetVM . NetworkProfile . NetworkInterfaces . First ( ) . ReferenceUri ;
166
+
167
+ // Get the NIC
168
+ var nicResourceGroupName = this . GetResourceGroupName ( nicId ) ;
169
+
170
+ var nicName = this . GetResourceName ( nicId , NetworkInterfaceResouce ) ;
171
+
172
+ nic = this . NetworkClient . NetworkManagementClient . NetworkInterfaces . GetVirtualMachineScaleSetNetworkInterface (
173
+ nicResourceGroupName ,
174
+ this . VirtualMachineScaleSetName ,
175
+ this . InstanceId ,
176
+ nicName ) ;
177
+ }
100
178
101
179
if ( nic . IpConfigurations . First ( ) . PublicIPAddress != null && ! string . IsNullOrEmpty ( nic . IpConfigurations . First ( ) . PublicIPAddress . Id ) )
102
180
{
@@ -174,7 +252,7 @@ public override void ExecuteCmdlet()
174
252
WindowStyle = ProcessWindowStyle . Hidden
175
253
} ;
176
254
177
- if ( this . LocalPath == null )
255
+ if ( string . IsNullOrEmpty ( this . LocalPath ) )
178
256
{
179
257
string scriptGuid = Guid . NewGuid ( ) . ToString ( ) ;
180
258
@@ -225,6 +303,7 @@ private string GetAddressFromPublicIPResource(string resourceId)
225
303
226
304
return address ;
227
305
}
306
+
228
307
private string GetResourceGroupName ( string resourceId )
229
308
{
230
309
return resourceId . Split ( '/' ) [ 4 ] ;
0 commit comments