Hello Everyone
I try to get a output of a Powershell script into a variable but with no luck.
Here the script who is based on this article: https://docs.microsoft.com/en-us/microsoft-365/enterprise/view-account-license-and-service-details-with-microsoft-365-powershell?view=o365-worldwide
$userUPN="AlF@M365EDU737345.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) ) { Write-Host $.SkuPartNumber } } }
Here is a example of the output: M365EDU_A5_STUDENT
I tried several things including Tee-Object but with no success. The variable keeps empty.
Can someone lead me in the right direction to get the output into a variable?
Thanks in advance!


whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer. Here is