Link to home
Start Free TrialLog in
Avatar of K B
K BFlag for United States of America

asked on

PowerShell: Why is this variable causing Microsoft.Online.Administration.AccountSkuDetails ?

I am presuming line #8 ($Bsku) is the origin of the issue.

$licensetype  = Get-MsolAccountSku
$AccountSkuId = $licensetype.accountskuid
$object = New-Object -TypeName PSObject
for($i = 0; $i -lt $AccountSkuId.count; $i++) {
    $Bsku = Get-MsolAccountSku | ? {$_.accountskuid -eq $AccountSkuId[$i]}
    for($j = 0; $j -lt $Bsku.ServiceStatus.count; $j++){
        $aservice = $Bsku.ServiceStatus[$j].ServicePlan.ServiceName
        $object | Add-Member -MemberType NoteProperty -Name AccountSkuID -Value $Bsku
        $object | Add-Member -MemberType NoteProperty -Name Service -Value $aservice
        Write-Output $object
    }
}   

Open in new window


User generated image
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of K B

ASKER

You are awesome thank you!
Avatar of oBdA
oBdA

Just had a closer look at your script, trying to understand what it is you're trying to do, instead of just fixing the obvious error.
Seems like you're trying to get a list of services for each SKU, only in a very complicated way? You already have everything you need in $LicenseType, so no need to run Get-MsolAccountSku over and over again.
Anyway, I can't test these, but I think they should do what you want.
Using the pipeline for real, in the spirit of Powershell:
Get-MsolAccountSku | ForEach-Object {
	$AccountSkuId = $_.AccountSkuId
	$_.ServiceStatus | Select-Object -Property @{n='AccountSkuId'; e={$AccountSkuId}}, @{n='Service'; e={$_.ServicePlan.ServiceName}}
}

Open in new window

Or, even shorter, but using a loop statement instead of the pipeline:
ForEach ($Sku In (Get-MsolAccountSku)) {
	$Sku.ServiceStatus | Select-Object -Property @{n='AccountSkuId'; e={$Sku.AccountSkuId}}, @{n='Service'; e={$_.ServicePlan.ServiceName}}
}

Open in new window

Avatar of K B

ASKER

Thank you.  I know I can learn from that.. I will study it.