Office 365 Powershell - Export user, license type, and company field to csv file

Posted by ASGJim on Server Fault See other posts from Server Fault or by ASGJim
Published on 2013-06-21T17:28:52Z Indexed on 2014/05/29 9:31 UTC
Read the original article Hit count: 554

Filed under:

I need to be able to export user name or email address (doesn't matter which), company (from the company field under the organization tab in a user account of the exchange admin console), and license type (e.g. exchange online e1, exchange online kiosk etc...)

I am able to export both values in two statements into two separate files but that doesn't do me much good.

I can export the username and license type with the following:

Get-MSOLUser | % { $user=$_; $_.Licenses | Select {$user.displayname},AccountSKuid } | Export-CSV "sample.csv" -NoTypeInformation

And, I can get the company values with the following:

Get-User | select company | Export-CSV sample.csv

Someone on another forum suggested this -

$index = @{}
Get-User | foreach-object {$index.Add($_.userprincipalname,$_.company)}
Get-MsolUser | ForEach-Object { write-host $_.userprincipalname, $index[$_.userprincipalname], $_.licenses.AccountSku.Skupartnumber}

That seems like it should work but it doesn't display any license info in my powershell, it's just blank. Also I wouldn't know how to export that to a csv file.

Any help would be appreciated. Thanks.

© Server Fault or respective owner

Related posts about powershell