none
Add UsageLocation and City to get-msollicense script RRS feed

  • Question

  • Hi guys,

    I'd need to extend the following script with additional fields, like:

    * UsageLocation

    * City

    In the output, these should be placed on the left side, starting with "usage location", then "city", then how it is written in the script. The whole list should be sorted based on usage location.

    Do you have any idea, how to extend the existing script, which is the following one:

    # The Output will be written to this file in the current working directory
    
    
    $LogFile = "Office_365_Licenses.<g class="gr_ gr_174 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling" data-gr-id="174" id="174">csv</g>"
    
    # Connect to Microsoft Online
    
    Import-Module MSOnline
    
    Connect-MsolService -Credential $Office365credentials
    
    write-host "Connecting to Office 365..."
    
    # Get a list of all <g class="gr_ gr_571 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling multiReplace" data-gr-id="571" id="571">licences</g> that exist within the tenant
    
    $licensetype = Get-MsolAccountSku | Where {$_.ConsumedUnits -<g class="gr_ gr_175 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling ins-del multiReplace" data-gr-id="175" id="175">ge</g>  1}
    
    # Loop through all <g class="gr_ gr_572 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling multiReplace" data-gr-id="572" id="572">licence</g> types found in the tenant
    
    <g class="gr_ gr_176 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling ins-del multiReplace" data-gr-id="176" id="176">foreach</g> ($license in $licensetype)
    
    {   
    
        # Build and write the Header for the CSV file
    
        $headerstring =  "DisplayName,UserPrincipalName,AccountSku"
    
        
    
        foreach ($row in $($license.ServiceStatus))
    
        {
    
            $headerstring = ($headerstring + "," +  $row.ServicePlan.servicename)
    
        }
    
        
    
        Out-File -FilePath $LogFile -InputObject $headerstring -Encoding UTF8 -append
    
        
    
        write-host ("Gathering users with the following subscription: " + $license.accountskuid)
    
        # Gather users for this particular AccountSku
    
        $users = Get-MsolUser -all | where {$_.isLicensed -eq "True" -and  $_.licenses.accountskuid -contains $license.accountskuid}
    
        # Loop through all users and write them to the CSV file
    
        foreach ($user in $users) {
    
            
    
            write-host ("Processing " + $user.displayname)
    
    $thislicense =  $user.licenses | Where-Object {$_.accountskuid -eq $license.accountskuid}
    
            $datastring = ($user.displayname + "," +  $user.userprincipalname + "," + $license.SkuPartNumber)
    
            
    
            foreach ($row in $($thislicense.servicestatus)) {
    
                
    
                # Build data string
    
                $datastring = ($datastring + "," + $($row.provisioningstatus))
    
            }
    
            
    
            Out-File -FilePath  $LogFile -InputObject $datastring -Encoding UTF8 -append
    
        }
    
    Out-File -FilePath $LogFile -InputObject  " " -Encoding UTF8 -append
    
    }           
    
    write-host ("Script Completed. Results available in " + $LogFile)


    Thanks in advance.




    Wednesday, May 2, 2018 9:55 AM

Answers

All replies