@@ -104,44 +104,46 @@ function New-AzsSubscription {
104
104
$PSBoundParameters.Add (" SubscriptionId" , $SubscriptionId )
105
105
}
106
106
107
- # Validate this resource does not exist.
108
- $_objectCheck = $null
109
- try {
110
- $_objectCheck = Get-AzsSubscription - SubscriptionId $SubscriptionId
111
- } catch {
112
- # No op
113
- } finally {
114
- if ($_objectCheck -ne $null ) {
115
- throw " A subscription with identifier $SubscriptionId already exists."
107
+ if ($PSCmdlet.ShouldProcess (" $SubscriptionId " , " Create new subscription" )) {
108
+
109
+ # Validate this resource does not exist.
110
+ $_objectCheck = $null
111
+ try {
112
+ $_objectCheck = Get-AzsSubscription - SubscriptionId $SubscriptionId
113
+ } catch {
114
+ # No op
115
+ } finally {
116
+ if ($_objectCheck -ne $null ) {
117
+ throw " A subscription with identifier $SubscriptionId already exists."
118
+ }
116
119
}
117
- }
118
120
119
- $NewServiceClient_params = @ {
120
- FullClientTypeName = ' Microsoft.AzureStack.Management.Subscriptions.SubscriptionsManagementClient'
121
- }
122
- $GlobalParameterHashtable = @ {}
123
- $NewServiceClient_params [' GlobalParameterHashtable' ] = $GlobalParameterHashtable
124
- $SubscriptionsManagementClient = New-ServiceClient @NewServiceClient_params
125
-
126
- $flattenedParameters = @ (' OfferId' , ' Id' , ' SubscriptionId' , ' State' , ' TenantId' , ' DisplayName' )
127
- $utilityCmdParams = @ {}
128
- $flattenedParameters | ForEach-Object {
129
- if ($PSBoundParameters.ContainsKey ($_ )) {
130
- $utilityCmdParams [$_ ] = $PSBoundParameters [$_ ]
121
+ $NewServiceClient_params = @ {
122
+ FullClientTypeName = ' Microsoft.AzureStack.Management.Subscriptions.SubscriptionsManagementClient'
131
123
}
132
- }
133
- $NewSubscription = New-SubscriptionObject @utilityCmdParams
134
-
135
- Write-Verbose - Message ' Performing operation create on $SubscriptionsManagementClient.'
136
- $TaskResult = $SubscriptionsManagementClient.Subscriptions.CreateOrUpdateWithHttpMessagesAsync ($SubscriptionId , $NewSubscription )
137
-
138
- if ($TaskResult ) {
139
- $GetTaskResult_params = @ {
140
- TaskResult = $TaskResult
124
+ $GlobalParameterHashtable = @ {}
125
+ $NewServiceClient_params [' GlobalParameterHashtable' ] = $GlobalParameterHashtable
126
+ $SubscriptionsManagementClient = New-ServiceClient @NewServiceClient_params
127
+
128
+ $flattenedParameters = @ (' OfferId' , ' Id' , ' SubscriptionId' , ' State' , ' TenantId' , ' DisplayName' )
129
+ $utilityCmdParams = @ {}
130
+ $flattenedParameters | ForEach-Object {
131
+ if ($PSBoundParameters.ContainsKey ($_ )) {
132
+ $utilityCmdParams [$_ ] = $PSBoundParameters [$_ ]
133
+ }
141
134
}
135
+ $NewSubscription = New-SubscriptionObject @utilityCmdParams
136
+
137
+ Write-Verbose - Message ' Performing operation create on $SubscriptionsManagementClient.'
138
+ $TaskResult = $SubscriptionsManagementClient.Subscriptions.CreateOrUpdateWithHttpMessagesAsync ($SubscriptionId , $NewSubscription )
142
139
143
- Get-TaskResult @GetTaskResult_params
140
+ if ($TaskResult ) {
141
+ $GetTaskResult_params = @ {
142
+ TaskResult = $TaskResult
143
+ }
144
144
145
+ Get-TaskResult @GetTaskResult_params
146
+ }
145
147
}
146
148
}
147
149
0 commit comments