@@ -162,58 +162,45 @@ function Get-AzMigrateHCIServerReplication {
162
162
163
163
# Occasionally, Get Machine Site will not return machine site even when the site exist,
164
164
# hence retry get machine site.
165
- $attempts = 4
166
- for ($i = 1 ; $i -le $attempts ; $i ++ ) {
167
- try {
168
- if ($siteType -eq $SiteTypes.VMwareSites ) {
169
- $siteObject = Az.Migrate\Get-AzMigrateSite @PSBoundParameters - ErrorVariable notPresent - ErrorAction SilentlyContinue
170
- }
171
- elseif ($siteType -eq $SiteTypes.HyperVSites ) {
172
- $siteObject = Az.Migrate.Internal\Get-AzMigrateHyperVSite @PSBoundParameters - ErrorVariable notPresent - ErrorAction SilentlyContinue
173
- }
165
+ if ($siteType -eq $SiteTypes.VMwareSites ) {
166
+ $siteObject = InvokeAzMigrateGetCommandWithRetries `
167
+ - CommandName ' Az.Migrate\Get-AzMigrateSite' `
168
+ - Parameters $PSBoundParameters `
169
+ - ErrorMessage " Machine site '$siteName ' with Type '$siteType ' not found."
170
+ } elseif ($siteType -eq $SiteTypes.HyperVSites ) {
171
+ $siteObject = InvokeAzMigrateGetCommandWithRetries `
172
+ - CommandName ' Az.Migrate.Internal\Get-AzMigrateHyperVSite' `
173
+ - Parameters $PSBoundParameters `
174
+ - ErrorMessage " Machine site '$siteName ' with Type '$siteType ' not found."
175
+ }
174
176
175
- if ($null -eq $siteObject ) {
176
- throw " Machine site not found."
177
- }
178
- else {
179
- $ProjectName = $siteObject.DiscoverySolutionId.Split (" /" )[8 ]
180
- }
177
+ # $siteObject is not null or exception would have been thrown
178
+ $ProjectName = $siteObject.DiscoverySolutionId.Split (" /" )[8 ]
181
179
182
- break ;
183
- }
184
- catch {
185
- if ($i -lt $attempts )
186
- {
187
- Write-Host " Machine site not found. Retrying in 30 seconds..."
188
- Start-Sleep - Seconds 30
189
- }
190
- else
191
- {
192
- throw " Machine site '$siteName ' with Type '$siteType ' not found."
193
- }
194
- }
195
- }
196
-
197
180
$null = $PSBoundParameters.Remove (' SiteName' )
198
181
199
- $null = $PSBoundParameters.Add (" Name" , " Servers-Migration-ServerMigration_DataReplication" )
182
+ # Get the migrate solution.
183
+ $amhSolutionName = " Servers-Migration-ServerMigration_DataReplication"
184
+ $null = $PSBoundParameters.Add (" Name" , $amhSolutionName )
200
185
$null = $PSBoundParameters.Add (" MigrateProjectName" , $ProjectName )
201
-
202
- $solution = Az.Migrate\Get-AzMigrateSolution @PSBoundParameters
203
- if ($solution -and ($solution.Count -ge 1 )) {
204
- $VaultName = $solution.DetailExtendedDetail.AdditionalProperties.vaultId.Split (" /" )[8 ]
205
- }
206
- else {
207
- throw " Solution not found."
208
- }
186
+
187
+ $solution = InvokeAzMigrateGetCommandWithRetries `
188
+ - CommandName ' Az.Migrate\Get-AzMigrateSolution' `
189
+ - Parameters $PSBoundParameters `
190
+ - ErrorMessage " No Data Replication Service Solution '$amhSolutionName ' found in resource group '$ResourceGroupName ' and project '$ProjectName '. Please verify your appliance setup."
209
191
210
192
$null = $PSBoundParameters.Remove (" Name" )
211
193
$null = $PSBoundParameters.Remove (" MigrateProjectName" )
194
+
195
+ $VaultName = $solution.DetailExtendedDetail.AdditionalProperties.vaultId.Split (" /" )[8 ]
196
+ if ([string ]::IsNullOrEmpty($VaultName )) {
197
+ throw " Azure Migrate Project not configured: missing replication vault. Setup Azure Migrate Project and run the Initialize-AzMigrateHCIReplicationInfrastructure script before proceeding."
198
+ }
212
199
213
200
$null = $PSBoundParameters.Add (" VaultName" , $VaultName )
214
201
$null = $PSBoundParameters.Add (" Name" , $ProtectedItemName )
215
202
216
- return Az.Migrate.Internal\Get-AzMigrateProtectedItem @PSBoundParameters - ErrorVariable notPresent - ErrorAction SilentlyContinue
203
+ return Az.Migrate.Internal\Get-AzMigrateProtectedItem @PSBoundParameters
217
204
}
218
205
219
206
if (($parameterSet -match ' List' ) -or ($parameterSet -eq ' GetByMachineName' )) {
@@ -234,23 +221,27 @@ function Get-AzMigrateHCIServerReplication {
234
221
$ProjectName = $projectIdArray [8 ]
235
222
}
236
223
224
+ $amhSolutionName = " Servers-Migration-ServerMigration_DataReplication"
237
225
$null = $PSBoundParameters.Add (" ResourceGroupName" , $ResourceGroupName )
238
- $null = $PSBoundParameters.Add (" Name" , " Servers-Migration-ServerMigration_DataReplication " )
226
+ $null = $PSBoundParameters.Add (" Name" , $amhSolutionName )
239
227
$null = $PSBoundParameters.Add (" MigrateProjectName" , $ProjectName )
240
-
241
- $solution = Az.Migrate\Get-AzMigrateSolution @PSBoundParameters
242
- if ($solution -and ($solution.Count -ge 1 )) {
243
- $VaultName = $solution.DetailExtendedDetail.AdditionalProperties.vaultId.Split (" /" )[8 ]
244
- }
245
- else {
246
- throw " Solution not found."
247
- }
228
+
229
+ $solution = InvokeAzMigrateGetCommandWithRetries `
230
+ - CommandName ' Az.Migrate\Get-AzMigrateSolution' `
231
+ - Parameters $PSBoundParameters `
232
+ - ErrorMessage " No Data Replication Service Solution '$amhSolutionName ' found in resource group '$ResourceGroupName ' and project '$ProjectName '. Please verify your appliance setup."
248
233
249
234
$null = $PSBoundParameters.Remove (" Name" )
250
235
$null = $PSBoundParameters.Remove (" MigrateProjectName" )
236
+
237
+ $VaultName = $solution.DetailExtendedDetail.AdditionalProperties.vaultId.Split (" /" )[8 ]
238
+ if ([string ]::IsNullOrEmpty($VaultName )) {
239
+ throw " Azure Migrate Project not configured: missing replication vault. Setup Azure Migrate Project and run the Initialize-AzMigrateHCIReplicationInfrastructure script before proceeding."
240
+ }
241
+
251
242
$null = $PSBoundParameters.Add (" VaultName" , $VaultName )
252
243
253
- $replicatingItems = Az.Migrate.Internal\Get-AzMigrateProtectedItem @PSBoundParameters - ErrorVariable notPresent - ErrorAction SilentlyContinue
244
+ $replicatingItems = Az.Migrate.Internal\Get-AzMigrateProtectedItem @PSBoundParameters
254
245
255
246
if ($parameterSet -eq " GetByMachineName" ) {
256
247
$replicatingItems = $replicatingItems | Where-Object { $_.Property.FabricObjectName -eq $MachineName }
@@ -274,7 +265,7 @@ function Get-AzMigrateHCIServerReplication {
274
265
$null = $PSBoundParameters.Add (" VaultName" , $VaultName )
275
266
$null = $PSBoundParameters.Add (" Name" , $ProtectedItemName )
276
267
277
- return Az.Migrate.Internal\Get-AzMigrateProtectedItem @PSBoundParameters - ErrorVariable notPresent - ErrorAction SilentlyContinue
268
+ return Az.Migrate.Internal\Get-AzMigrateProtectedItem @PSBoundParameters
278
269
}
279
270
}
280
271
}
0 commit comments