Azure / Azure/azure-powershell

issue in custom/Initialize-AzMigrateReplicationInfrastructure.ps1

Open
#20,487 6 comments 0 reactions 0 assignees View on GitHub
bug customer-reported Migrate needs-team-attention Service Attention
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
2d 17h
Merged PRs (30d)
51

Description

### Description

When running command Initialize-AzMigrateReplicationInfrastructure (with parameters) got error
Initialize-AzMigrateReplicationInfrastructure : Cannot validate argument on parameter 'ObjectId'. The argument is null
or empty. Provide an argument that is not null or empty, and then try the command again.

I guess issue is here
Azure/azure-powershell/blob/main/src/Migrate/custom/Initialize-AzMigrateReplicationInfrastructure.ps1
452: $kvspnid = (Get-AzADServicePrincipal -DisplayName "Azure Key Vault" )[0].Id
(Get-AzADServicePrincipal -DisplayName "Azure Key Vault" ) returns object, not an array

### Issue script & Debug output

```PowerShell
output is huge, but not correlated with problem
...
DEBUG: [Common.Authentication]: Received token with LoginType 'User', Tenant: '############',
UserId: '############'
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/subscriptions/############/resourceGroups/rg-migrate2/resources?ap
i-version=2021-04-01

Headers:
x-ms-client-request-id : f923488f-7eec-422b-86f5-7bb43ea3740c
accept-language : en-US

Body:

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Pragma : no-cache
x-ms-ratelimit-remaining-subscription-reads: 11999
x-ms-request-id : 9d6b10d3-89bf-4922-ac88-496868d18855
x-ms-correlation-request-id : 9d6b10d3-89bf-4922-ac88-496868d18855
x-ms-routing-request-id : GERMANYWESTCENTRAL:20221220T112113Z:9d6b10d3-89bf-4922-ac88-496868d18855
Strict-Transport-Security : max-age=31536000; includeSubDomains
X-Content-Type-Options : nosniff
Cache-Control : no-cache
Date : Tue, 20 Dec 2022 11:21:12 GMT

Body:
{
"value": [
{
"id":
"/subscriptions/############/resourceGroups/rg-migrate2/providers/Microsoft.KeyVault/vaults/mig
ratekv466521626",
"name": "migratekv466521626",
"type": "Microsoft.KeyVault/vaults",
"location": "centralus",
"tags": {
"Migrate Project": "vmware-migrate2"
}
},
{
"id":
"/subscriptions/############/resourceGroups/rg-migrate2/providers/Microsoft.KeyVault/vaults/vmw
are-migrate5134kv",
"name": "vmware-migrate5134kv",
"type": "Microsoft.KeyVault/vaults",
"location": "centralus",
"tags": {}
},
{
"id":
"/subscriptions/############/resourceGroups/rg-migrate2/providers/Microsoft.Migrate/assessmentP
rojects/azAppliance8138project",
"name": "azAppliance8138project",
"type": "Microsoft.Migrate/assessmentProjects",
"kind": "Migrate",
"location": "centralus",
"tags": {
"Migrate Project": "vmware-migrate2"
}
},
{
"id":
"/subscriptions/############/resourceGroups/rg-migrate2/providers/Microsoft.Migrate/migrateproj
ects/vmware-migrate2",
"name": "vmware-migrate2",
"type": "Microsoft.Migrate/migrateprojects",
"location": "centralus",
"tags": {
"Migrate Project": "vmware-migrate2"
}
},
{
"id":
"/subscriptions/############/resourceGroups/rg-migrate2/providers/Microsoft.OffAzure/MasterSite
s/vmware-migrate5134mastersite",
"name": "vmware-migrate5134mastersite",
"type": "Microsoft.OffAzure/MasterSites",
"kind": "Migrate",
"location": "centralus",
"tags": {
"Migrate Project": "vmware-migrate2"
}
},
{
"id":
"/subscriptions/############/resourceGroups/rg-migrate2/providers/Microsoft.OffAzure/VMwareSite
s/azAppliance8138site",
"name": "azAppliance8138site",
"type": "Microsoft.OffAzure/VMwareSites",
"kind": "Migrate",
"location": "centralus",
"tags": {
"Migrate Project": "vmware-migrate2"
}
},
{
"id":
"/subscriptions/############/resourceGroups/rg-migrate2/providers/Microsoft.RecoveryServices/va
ults/azAppliance8138vault",
"name": "azAppliance8138vault",
"type": "Microsoft.RecoveryServices/vaults",
"sku": {
"name": "RS0",
"tier": "Standard"
},
"location": "centralus",
"tags": {
"Migrate Project": "vmware-migrate2"
}
},
{
"id":
"/subscriptions/############/resourceGroups/rg-migrate2/providers/Microsoft.ServiceBus/namespac
es/migratesbns466521626",
"name": "migratesbns466521626",
"type": "Microsoft.ServiceBus/namespaces",
"sku": {
"name": "Standard",
"tier": "Standard"
},
"location": "centralus",
"tags": {
"Migrate Project": "vmware-migrate2"
}
},
{
"id":
"/subscriptions/############/resourceGroups/rg-migrate2/providers/Microsoft.Storage/storageAcco
unts/migrategwsa466521626",
"name": "migrategwsa466521626",
"type": "Microsoft.Storage/storageAccounts",
"sku": {
"name": "Standard_LRS",
"tier": "Standard"
},
"kind": "Storage",
"location": "centralus",
"tags": {
"Migrate Project": "vmware-migrate2"
}
},
{
"id":
"/subscriptions/############/resourceGroups/rg-migrate2/providers/Microsoft.Storage/storageAcco
unts/migratelsa466521626",
"name": "migratelsa466521626",
"type": "Microsoft.Storage/storageAccounts",
"sku": {
"name": "Standard_LRS",
"tier": "Standard"
},
"kind": "Storage",
"location": "centralus",
"tags": {
"Migrate Project": "vmware-migrate2"
}
}
]
}

DEBUG: 15:21:15 - GetAzureResourceCmdlet end processing.
Initialize-AzMigrateReplicationInfrastructure : Cannot validate argument on parameter 'ObjectId'. The argument is null
or empty. Provide an argument that is not null or empty, and then try the command again.
At line:1 char:1
+ Initialize-AzMigrateReplicationInfrastructure `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Initialize-AzMi...nInfrastructure], ParameterBindingValidationExceptio
n
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Initialize-AzMigrateReplicationInfrastructure
```

### Environment data

```PowerShell
Name Value
---- -----
PSVersion 5.1.19041.1682
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.1682
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
```

### Module versions

```PowerShell
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 2.10.4 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear...
Script 2.1.0 Az.Migrate {Get-AzMigrateDiscoveredServer, Get-AzMigrateJob, Get-AzMi...
Script 6.5.1 Az.Resources {Export-AzResourceGroup, Export-AzTemplateSpec, Get-AzDeny...
```

### Error output

```PowerShell
Message : Cannot validate argument on parameter 'ObjectId'. The argument is null or empty. Provide an argument t
hat is not null or empty, and then try the command again.
StackTrace : at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcCont
ext, Exception exception)
at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame fr
ame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame fr
ame)
at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
at System.Management.Automation.PSScriptCmdlet.RunClause(Action`1 clause, Object dollarUnderbar, Ob
ject inputToProcess)
at System.Management.Automation.PSScriptCmdlet.DoProcessRecord()
at System.Management.Automation.CommandProcessor.ProcessRecord()
Exception : System.Management.Automation.ParameterBindingValidationException
InvocationInfo : {Get-AzRoleAssignment}
Line : $gwyRoleAssignments = Get-AzRoleAssignment -ObjectId $kvspnid -Scope $gwyStorageAccoun
t.Id -ErrorVariable notPresent -ErrorAction SilentlyContinue

Position : At C:\Program Files\WindowsPowerShell\Modules\Az.Migrate\2.1.0\custom\Initialize-AzMigrateReplicationI
nfrastructure.ps1:455 char:70
+ ... $gwyRoleAssignments = Get-AzRoleAssignment -ObjectId $kvspnid -Scope ...
+ ~~~~~~~~
HistoryId : 14

Message : The argument is null or empty. Provide an argument that is not null or empty, and then try the command
again.
StackTrace : at System.Management.Automation.ValidateNotNullOrEmptyAttribute.Validate(Object arguments, EngineIn
trinsics engineIntrinsics)
at System.Management.Automation.ParameterBinderBase.BindParameter(CommandParameterInternal paramete
r, CompiledCommandParameter parameterMetadata, ParameterBindingFlags flags)
Exception : System.Management.Automation.ValidationMetadataException
InvocationInfo : {Get-AzRoleAssignment}
Line : $gwyRoleAssignments = Get-AzRoleAssignment -ObjectId $kvspnid -Scope $gwyStorageAccoun
t.Id -ErrorVariable notPresent -ErrorAction SilentlyContinue

Position : At C:\Program Files\WindowsPowerShell\Modules\Az.Migrate\2.1.0\custom\Initialize-AzMigrateReplicationI
nfrastructure.ps1:455 char:70
+ ... $gwyRoleAssignments = Get-AzRoleAssignment -ObjectId $kvspnid -Scope ...
+ ~~~~~~~~
HistoryId : 14

The Azure PowerShell team is listening, please let us know how we are doing: https://aka.ms/azpssurvey?Q_CHL=ERROR.

DEBUG: AzureQoSEvent: Module: Az.Accounts:2.10.4; CommandName: Resolve-AzError; PSVersion: 5.1.19041.1682; IsSuccess:
True; Duration: 00:00:00.0358862
DEBUG: 15:29:14 - [ConfigManager] Got nothing from [EnableDataCollection], Module = [], Cmdlet = []. Returning default
value [True].
DEBUG: 15:29:14 - ResolveError end processing.
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.