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

K B
K B used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
At the end of line 8, you'd need
... -Value $Bsku.accountskuid
K B

Author

Commented:
You are awesome thank you!
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
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

K B

Author

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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial