简体   繁体   English

PowerShell列出所有O365用户和相关许可证

[英]PowerShell List all O365 Users and Associated Licenses

I am trying to get a list of all O365 users from a tenant, and the individual licenses that are assigned to them. 我正在尝试从租户获取所有O365用户的列表,以及分配给他们的单个许可证。 The output needs to be in the following format (note that users with more than one license are listed multiple times): 输出必须采用以下格式(请注意,多次列出了具有多个许可证的用户):

UPN | UPN | License user1 | 许可证用户1 | standardpack user1 | standardpack user1 | plannerstandalone user2 | plannerstandalone user2 | enterprisepack user2 | enterprisepack user2 | power_bi_standard user2 | power_bi_standard user2 | ems EMS

I can get the information using this: 我可以使用以下信息:

$groupOfUsers = Get-MsolUser -all | where { $_.IsLicensed -eq $True }
$licenses = foreach ($individual in $groupOfUsers) 
{ 
    $allLicenses = $individual.licenses | Select -ExpandProperty AccountSkuId
        foreach ($lic in $allLicenses)
            { write-host = $individual.UserPrincipalName $lic }
} 

What I would like to do is have this output in a format that I can eventually import into SQL - so a table format or something that I can export to csv would be a great start. 我想做的就是以最终可以导入到SQL中的格式输出此输出-因此表格式或可以导出到csv的内容将是一个很好的开始。

Any help would be appreciated. 任何帮助,将不胜感激。

try this 尝试这个

$groupOfUsers = Get-MsolUser -all | where { $_.IsLicensed -eq $True }

$results = foreach ($user in $groupOfUsers) {
    $licenses = $user.licenses.accountskuid
    foreach ($license in $licenses) {
        [pscustomobject]@{
            UPN = $user.userprincipalname
            License = $license
        }
    }
}

$results

$results | Export-Csv c:\temp\o365licenses.csv -NoTypeInformation

start c:\temp\0365licenses.csv

get the list of licenses using powershell Get-MsolAccountSku 使用powershell Get-MsolAccountSku获取许可证列表

AND Get-MsolUser | AND Get-MsolUser | Where-Object {($_.licenses).AccountSkuId -match "EnterprisePremium"} 哪里对象{($ _。licenses).AccountSkuId -match“ EnterprisePremium”}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM