Azure / azure-iot-remote-monitoring

Azure IoT Remote Monitoring preconfigured solution
Other
249 stars 221 forks source link

'build.cmd local' throws an exception (Cannot validate argument on parameter 'Tenant'.) #454

Closed nkgami closed 3 years ago

nkgami commented 6 years ago

With Azure PowerShell 4.4.0 or newer, we get exception at Common\Deployment\DeploymentLib.ps1:904 like below.

Select an option from the above list: 1 2017-11-20T04:54:39.4788171+00:00 - SubscriptionId changed to Set-AzureRmContext : Cannot validate argument on parameter 'Tenant'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. At C:\temp\azure-iot-remote-monitoring-master\azure-iot-remote-monitoring-maste r\Common\Deployment\DeploymentLib.ps1:904 char:78 + Select-AzureRmSubscription -SubscriptionName $rmSubscription.Name -TenantId $rm ... + \~\~\~

  • CategoryInfo : InvalidData: (:) [Set-AzureRmContext], Parameter BindingValidationException
  • FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Azure .Commands.Profile.SetAzureRMContextCommand

Available locations: \<snipped>

This is because $rmSubscription doesn't have property 'Tenant', we should use 'TenantId' instead.

$rmSubscription = Get-AzureRmSubscription -SubscriptionId $global:SubscriptionId
 Select-AzureRmSubscription -SubscriptionName $rmSubscription.Name -TenantId $rmSubscription.Tenant.Id
$rmSubscription | Get-Member
TypeName: Microsoft.Azure.Commands.Profile.Models.PSAzureSubscription

Name                      MemberType Definition                                                                     
----                      ---------- ----------                                                                     
Equals                    Method     bool Equals(System.Object obj)                                                 
GetHashCode               Method     int GetHashCode()                                                              
GetType                   Method     type GetType()                                                                 
ToString                  Method     string ToString()                                                              
CurrentStorageAccountName Property   string CurrentStorageAccountName {get;}                                        
ExtendedProperties        Property   System.Collections.Generic.IDictionary[string,string] ExtendedProperties {get;}
Id                        Property   string Id {get;set;}                                                           
Name                      Property   string Name {get;set;}                                                         
State                     Property   string State {get;set;}                                                        
TenantId                  Property   string TenantId {get;set;}  

With Azure PowerShell 4.2.1 no exception is thrown, but actually we pass null to '-TenantId' and Select-AzureRmSubscription method just ignores this option. Please consider to change 'Tenant.Id' to 'TenantId'.

ksaye commented 5 years ago

Thanks for identifying this, it solved my problem too.

magixus commented 4 years ago

I'am using powershell 5.1+ and AzureRM 6.13.1 and fixed this issue by replacing Tenant.Id by TenentId like that :

Select-AzureRmSubscription -SubscriptionName $rmSubscription.Name -TenantId $rmSubscription.TenantId
ankitscribbles commented 3 years ago

Note: As of December 10th 2020, Remote Monitoring solution accelerator is no longer supported. All supporting repositories have been archived.