【发布时间】:2017-09-04 10:40:36
【问题描述】:
我正在尝试查找已分配特定许可类型的所有用户。 我基本上是在尝试将我的 Azure 模块 v1 命令转换为 Azure 模块 v2 命令。如何获得与 Azure 模块 v1 命令相同的结果?
Azure V1:
$OutputFile = "C:\Export\O365LicensedADEnabledUsers.csv"
$T1 = @()
$O365Users = Get-MsolUser -All
ForEach ($O365User in $O365Users)
{
$ADuser = Get-ADUser -Filter { UserPrincipalName -eq $O365User.UserPrincipalName } -Properties whenCreated, Department, Company, Enabled
If (($ADUser.Enabled -eq $true) -and ($O365User.isLicensed -eq $true))
{
$T1 += New-Object psobject -Property @{
CollectDate = $(Get-Date);
ADUserUPN = $($ADUser.UserPrincipalName);
O365UserUPN = $($O365User.UserPrincipalName);
ADUserCreated = $($ADUser.whenCreated);
ADUserDepartment = $($ADUser.Department);
ADUserCompany = $($ADUser.Company);
ADUserEnabled = $($ADUser.Enabled);
O365Licensed = $($O365User.isLicensed)
}
}
}
$T1 = $T1 | Sort-Object -Property ADUserCreated
$T1 | Format-Table
$T1 | Export-Csv -Path $OutputFile -NoTypeInformation
Write-Host "Output to $OutputFile"
Azure V2:
AFAIK,Azure AD V2 powershell 中没有 isLicensed 属性。我找到了 AssignedLicenses 属性而不是这个。但我不确定。
$OutputFile = "C:\Export\O365LicensedADEnabledUsers.csv"
$T1 = @()
$O365Users = Get-AzureADUser -All $true
ForEach ($O365User in $O365Users)
{
$ADuser = Get-ADUser -Filter { UserPrincipalName -eq $O365User.UserPrincipalName } -Properties whenCreated, Department, Company, Enabled
If (($ADUser.Enabled -eq $true) -and ($O365User.AssignedLicenses -ne $null))
{
$T1 += New-Object psobject -Property @{
CollectDate = $(Get-Date);
ADUserUPN = $($ADUser.UserPrincipalName);
O365UserUPN = $($O365User.UserPrincipalName);
ADUserCreated = $($ADUser.whenCreated);
ADUserDepartment = $($ADUser.Department);
ADUserCompany = $($ADUser.Company);
ADUserEnabled = $($ADUser.Enabled);
O365Licensed = $($O365User.AssignedLicenses)
}
}
}
$T1 = $T1 | Sort-Object -Property ADUserCreated
$T1 | Format-Table
$T1 | Export-Csv -Path $OutputFile -NoTypeInformation
Write-Host "Output to $OutputFile"
【问题讨论】:
-
您可能打算在第二个中使用
Get-AzureAdUser而不是Get-ADUser。似乎 AssignedLicenses 属性永远不会为空,因此您的检查将不起作用。我猜您必须检查它是否包含您认为有效的 SKU。 User entity documentation, AssignedLicense documentation -
您可以通过
Get-AzureAdSubscribedSku获取租户订阅的 SKU。然后以某种方式找出其中哪些对您的用例有效,然后检查用户是否拥有其中一个。 -
感谢您的回答。你能给我示例脚本吗?
标签: powershell azure-active-directory export-to-csv