@@ -56,12 +56,9 @@ Function Get-TenantInformation{
5656 # Get tenant details
5757 $Tenant = Get-MonkeyMSGraphOrganization - TenantId $tid
5858 If ($Tenant ){
59- # Set Tenant info var
60- Set-Variable Tenant - Value $Tenant - Scope Script - Force
6159 If ($O365Object.isConfidentialApp ){
6260 # Set Userprincipalname var
6361 If ($O365Object.auth_tokens.MSGraph.psobject.Properties.Item (' clientId' )){
64- Set-Variable userPrincipalName - Value $O365Object.auth_tokens.MSGraph.clientId.ToString () - Scope Script - Force
6562 $O365Object.userPrincipalName = $O365Object.auth_tokens.MSGraph.clientId.ToString ()
6663 }
6764 Else {
@@ -72,23 +69,19 @@ Function Get-TenantInformation{
7269 Tags = @ (' EIDUserPrincipalNameError' );
7370 }
7471 Write-Warning @msg
75- Set-Variable userPrincipalName - Value $null - Scope Script - Force
7672 $O365Object.userPrincipalName = $O365Object.initParams.ClientId
7773 }
7874 }
7975 Else {
8076 # Set Userprincipalname var
8177 If ($O365Object.auth_tokens.MSGraph.psobject.Properties.Item (' UserInfo' )){
8278 $O365Object.userPrincipalName = $O365Object.auth_tokens.MSGraph.UserInfo.DisplayableId.ToString ()
83- Set-Variable userPrincipalName - Value $O365Object.auth_tokens.MSGraph.UserInfo.DisplayableId.ToString () - Scope Script - Force
8479 }
8580 ElseIf ($O365Object.auth_tokens.MSGraph.psobject.Properties.Item (' userPrincipalName' )){
8681 $O365Object.userPrincipalName = $O365Object.auth_tokens.MSGraph.userPrincipalName
87- Set-Variable userPrincipalName - Value $O365Object.auth_tokens.MSGraph.userPrincipalName - Scope Script - Force
8882 }
8983 ElseIf ($O365Object.auth_tokens.MSGraph.psobject.Properties.Item (' Account' )){
9084 $O365Object.userPrincipalName = $O365Object.auth_tokens.MSGraph.Account.Username
91- Set-Variable userPrincipalName - Value $O365Object.auth_tokens.MSGraph.Account.Username - Scope Script - Force
9285 }
9386 Else {
9487 $msg = @ {
@@ -98,14 +91,13 @@ Function Get-TenantInformation{
9891 Tags = @ (' EIDUserPrincipalNameError' );
9992 }
10093 Write-Warning @msg
101- Set-Variable userPrincipalName - Value $null - Scope Script - Force
10294 $O365Object.userPrincipalName = $null
10395 }
10496 }
10597 # Set properties
106- $O365Object.Tenant.tenantName = $Tenant. displayName
98+ $O365Object.Tenant.tenantName = ( $Tenant | Select-Object - ExpandProperty displayName - ErrorAction Ignore)
10799 $O365Object.Tenant.companyInfo = $Tenant
108- $O365Object.Tenant.tenantId = $Tenant.Id
100+ $O365Object.Tenant.tenantId = ( $Tenant | Select-Object - ExpandProperty Id - ErrorAction Ignore)
109101 # Get subscribed SKUs
110102 $O365Object.Tenant.sku = Get-MonkeyMSGraphSuscribedSku
111103 If ($null -ne $O365Object.Tenant.sku ){
@@ -121,7 +113,7 @@ Function Get-TenantInformation{
121113 }
122114 Else {
123115 # Throw error
124- throw (" [TenantError] {0}: {1} " -f " Unable to get tenant information" , $_ .Exception.Message )
116+ throw (" [TenantError] {0}" -f " Unable to get tenant information" )
125117 }
126118 }
127119 Else {
@@ -146,6 +138,7 @@ Function Get-TenantInformation{
146138 MessageData = $_ ;
147139 callStack = (Get-PSCallStack | Select-Object - First 1 );
148140 logLevel = ' verbose' ;
141+ Verbose = $O365Object.verbose ;
149142 Tags = @ (' EIDTenantError' );
150143 }
151144 Write-Verbose @msg
0 commit comments