@freumich ,
Thank you for your query . I understand that you are trying to get details of AzureAD license Plan through the mentioned code snippet and store the output in a variable.
I modified the above code snippet a little so that rather than posting the output to the console using Write-Host
, it now stores that value as an array in the variable called $userSku
.
$userUPN = "abcdef@test21.onmicrosoft.com"
$licensePlanList = Get-AzureADSubscribedSku
$userList = Get-AzureADUser -ObjectID $userUPN | Select -ExpandProperty AssignedLicenses | Select SkuID
$userList | ForEach { $sku=$_.SkuId ; $licensePlanList | ForEach { If ( $sku -eq $_.ObjectId.substring($_.ObjectId.length - 36, 36) ) { $userSku+=$_.SkuPartNumber}} }
I would also suggest to clear the variable array if you are going to run the above code for multiple users in the tenant since running the same thing twice will keep appending the value in $userSku
value .
Clear-Variable -Name userSku
The following is the output of the above modified scripts and you can see the output being stored to the $userSku
array variable.
You can access each element in the array as shown below.
Hope this helps. In case you have any further queries , please let us know and we will be happy to help . Should the information be helpful , please feel free to accept the post as answer which may help others with similar queries.
Thank you.
----------------------------------------------------------------------------------------------------------------------------------------------------------
- Please don't forget to click on whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer. Here is how
- Want a reminder to come back and check responses? Here is how to subscribe to a notification
- If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators