Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
460 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 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...