13
13
// ----------------------------------------------------------------------------------
14
14
15
15
using Microsoft . Azure . Commands . RemoteApp ;
16
- using Microsoft . Azure . Management . RemoteApp ;
17
16
using Microsoft . Azure . Management . RemoteApp . Models ;
18
17
using System ;
19
18
using System . Management . Automation ;
20
19
using System . Net ;
21
20
22
21
namespace Microsoft . Azure . Management . RemoteApp . Cmdlets
23
22
{
24
- [ Cmdlet ( VerbsCommon . Set , "AzureRemoteAppCollection" ) , OutputType ( typeof ( TrackingResult ) ) ]
23
+ [ Cmdlet ( VerbsCommon . Set , "AzureRemoteAppCollection" , DefaultParameterSetName = DescriptionOnly ) , OutputType ( typeof ( TrackingResult ) ) ]
25
24
public class SetAzureRemoteAppCollection : RdsCmdlet
26
25
{
27
26
private const string DomainJoined = "DomainJoined" ;
28
- private const string NoDomain = "NoDomain" ;
27
+ private const string RdpPropertyOnly = "RdpPropertyOnly" ;
28
+ private const string DescriptionOnly = "DescriptionOnly" ;
29
+ private const string PlanOnly = "PlanOnly" ;
29
30
30
31
[ Parameter ( Mandatory = true ,
31
32
Position = 0 ,
@@ -35,37 +36,38 @@ public class SetAzureRemoteAppCollection : RdsCmdlet
35
36
[ Alias ( "Name" ) ]
36
37
public string CollectionName { get ; set ; }
37
38
38
- [ Parameter ( Mandatory = false ,
39
- Position = 1 ,
39
+ [ Parameter ( Mandatory = true ,
40
40
ValueFromPipelineByPropertyName = true ,
41
+ ParameterSetName = PlanOnly ,
41
42
HelpMessage = "Plan to use for this collection. Use Get-AzureRemoteAppPlan to see the plans available." ) ]
42
43
[ ValidateNotNullOrEmpty ]
43
44
public string Plan { get ; set ; }
44
45
45
- [ Parameter ( Mandatory = false ,
46
- Position = 2 ,
46
+ [ Parameter ( Mandatory = true ,
47
47
ValueFromPipelineByPropertyName = true ,
48
48
ParameterSetName = DomainJoined ,
49
49
HelpMessage = "Credentials of a user that has permission to add computers to the domain." ) ]
50
50
[ ValidateNotNull ]
51
51
public PSCredential Credential { get ; set ; }
52
52
53
- [ Parameter ( Mandatory = false ,
53
+ [ Parameter ( Mandatory = true ,
54
54
ValueFromPipelineByPropertyName = true ,
55
+ ParameterSetName = DescriptionOnly ,
55
56
HelpMessage = "Description of what this collection is used for." ) ]
56
- [ ValidateNotNullOrEmpty ]
57
+ [ ValidateNotNull ]
57
58
public string Description { get ; set ; }
58
59
59
- [ Parameter ( Mandatory = false ,
60
+ [ Parameter ( Mandatory = true ,
60
61
ValueFromPipelineByPropertyName = true ,
62
+ ParameterSetName = RdpPropertyOnly ,
61
63
HelpMessage = "Used to allow RDP redirection." ) ]
62
- [ ValidateNotNullOrEmpty ]
64
+ [ ValidateNotNull ]
63
65
public string CustomRdpProperty { get ; set ; }
64
66
65
67
public override void ExecuteCmdlet ( )
66
68
{
67
69
NetworkCredential creds = null ;
68
- CollectionCreationDetails details = null ;
70
+ CollectionUpdateDetails details = null ;
69
71
OperationResultWithTrackingId response = null ;
70
72
Collection collection = null ;
71
73
bool forceRedeploy = false ;
@@ -76,57 +78,61 @@ public override void ExecuteCmdlet()
76
78
return ;
77
79
}
78
80
79
- details = new CollectionCreationDetails ( )
80
- {
81
- Name = CollectionName ,
82
- PlanName = String . IsNullOrWhiteSpace ( Plan ) ? collection . PlanName : Plan ,
83
- Description = String . IsNullOrWhiteSpace ( Description ) ? collection . Description : Description ,
84
- CustomRdpProperty = String . IsNullOrWhiteSpace ( CustomRdpProperty ) ? collection . CustomRdpProperty : CustomRdpProperty ,
85
- TemplateImageName = collection . TemplateImageName
86
- } ;
81
+ details = new CollectionUpdateDetails ( ) ;
87
82
88
- switch ( ParameterSetName )
83
+ if ( Credential != null )
89
84
{
90
- case DomainJoined :
91
- {
92
- if ( collection . AdInfo == null )
93
- {
94
- ErrorRecord er = RemoteAppCollectionErrorState . CreateErrorRecordFromString (
95
- Commands_RemoteApp . AadInfoCanNotBeAddedToCloudOnlyCollectionMessage ,
96
- String . Empty ,
97
- Client . Collections ,
98
- ErrorCategory . InvalidArgument ) ;
99
- ThrowTerminatingError ( er ) ;
100
- }
101
-
102
- details . AdInfo = new ActiveDirectoryConfig ( ) ;
103
- details . VNetName = collection . VNetName ;
104
- details . AdInfo . DomainName = collection . AdInfo . DomainName ;
105
- details . AdInfo . OrganizationalUnit = collection . AdInfo . OrganizationalUnit ;
106
-
107
- if ( Credential != null )
108
- {
109
- creds = Credential . GetNetworkCredential ( ) ;
110
- details . AdInfo . UserName = creds . UserName ;
111
- details . AdInfo . Password = creds . Password ;
112
- }
113
-
114
- if ( String . Equals ( "Inactive" , collection . Status , StringComparison . OrdinalIgnoreCase ) )
115
- {
116
- // the collection may have failed due to bad domain join information before,
117
- // re-trying with the new information
118
- forceRedeploy = true ;
119
- }
120
-
121
- break ;
122
- }
85
+ if ( collection . AdInfo == null )
86
+ {
87
+ ErrorRecord er = RemoteAppCollectionErrorState . CreateErrorRecordFromString (
88
+ Commands_RemoteApp . AadInfoCanNotBeAddedToCloudOnlyCollectionMessage ,
89
+ String . Empty ,
90
+ Client . Collections ,
91
+ ErrorCategory . InvalidArgument ) ;
92
+ ThrowTerminatingError ( er ) ;
93
+ }
94
+
95
+ details . AdInfo = new ActiveDirectoryConfig ( ) ;
96
+
97
+ creds = Credential . GetNetworkCredential ( ) ;
98
+ details . AdInfo . UserName = Credential . UserName ;
99
+ details . AdInfo . Password = creds . Password ;
100
+ details . AdInfo . DomainName = collection . AdInfo . DomainName ;
101
+ details . AdInfo . OrganizationalUnit = collection . AdInfo . OrganizationalUnit ;
102
+
103
+ if ( String . Equals ( "Inactive" , collection . Status , StringComparison . OrdinalIgnoreCase ) )
104
+ {
105
+ // the collection may have failed due to bad domain join information before,
106
+ // re-trying with the new information
107
+ forceRedeploy = true ;
108
+ }
109
+ }
110
+ else if ( Plan != null )
111
+ {
112
+ details . PlanName = Plan ;
113
+ }
114
+ else if ( Description != null )
115
+ {
116
+ details . Description = Description ;
117
+ }
118
+ else if ( CustomRdpProperty != null )
119
+ {
120
+ details . CustomRdpProperty = CustomRdpProperty ;
121
+ }
122
+ else
123
+ {
124
+ ErrorRecord er = RemoteAppCollectionErrorState . CreateErrorRecordFromString (
125
+ "At least one parameter must be set with this cmdlet" ,
126
+ String . Empty ,
127
+ Client . Collections ,
128
+ ErrorCategory . InvalidArgument ) ;
129
+ ThrowTerminatingError ( er ) ;
123
130
}
124
131
125
132
response = CallClient ( ( ) => Client . Collections . Set ( CollectionName , forceRedeploy , false , details ) , Client . Collections ) ;
126
133
if ( response != null )
127
134
{
128
- TrackingResult trackingId = new TrackingResult ( response ) ;
129
- WriteObject ( trackingId ) ;
135
+ WriteTrackingId ( response ) ;
130
136
}
131
137
}
132
138
}
0 commit comments