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


2017-03-15_1111.png
LVL 8
K BAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
At the end of line 8, you'd need
... -Value $Bsku.accountskuid
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
K BAuthor Commented:
You are awesome thank you!
0
oBdACommented:
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

0
K BAuthor Commented:
Thank you.  I know I can learn from that.. I will study it.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.