We help IT Professionals succeed at work.

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

332 Views
Last Modified: 2017-03-15
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

CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
K B

Author

Commented:
You are awesome thank you!
CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable 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.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions