Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
449 views
in Technique[技术] by (71.8m points)

office365 - Powershell script handling output when no input is found

I've been using this script in order to pull our clients' Office 365 licensing information from their tenant via Powershell and needed some help with the fine tuning. Currently the script grabs the licensing from the tenant, matches the skupartnumber (subscription ID) of the subscriptions to the csv I have of Microsoft subscription names, then outputs it in a table to the console using the friendly name of the subscription.

It works perfectly, however when I come across a subscription in the wild I don't have in my csv the table is creating with all of the data off by one row (the csv is pretty exhaustive but I need to fix this before deploying this tool to the rest of my team because these IDs often change). This is easily fixed by adding this skupartnumber to the csv, however I would like this to simply display the skupartnumber in the console instead of breaking the table.

I've been playing around with it this afternoon but there have been a lot of distractions today, can anyone point me in the right direction for the best way to fix my output? Thanks for any help I can get!

$sku = Get-MsolAccountSku | select-object skupartnumber,ActiveUnits,suspendedUnits,ConsumedUnits | sort-object -property skupartnumber

$skudata = import-csv -Header friendlyname,skupartnumber "C:PShellcspcatalogalphabet.csv" | where-object {$sku.skupartnumber -eq $_.skupartnumber} | sort-object -property skupartnumber

$result = for ($n = 0; $n -lt @($skudata).Count; $n++) {
    # output the data as PSObject that gets collected in variable $result
    [PsCustomObject]@{
        Subscription = @($skudata.friendlyname)[$n]
        Active        = $sku.ActiveUnits[$n]
        Suspended     = $sku.SuspendedUnits[$n]
        Assigned      = $sku.ConsumedUnits[$n]
    }
}

# output on screen
$result | Format-Table -AutoSize
question from:https://stackoverflow.com/questions/65876480/powershell-script-handling-output-when-no-input-is-found

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...