Azure Active Directory V2 PowerShell - 查找所有获得许可的 Office 365 用户
Azure Active Directory V2 PowerShell - Finding all licenced Office 365 users
我正在尝试查找已分配特定许可类型的所有用户。
我基本上是在尝试将我的 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"
通过 Azure AD V2 PowerShell 检查用户是否拥有许可证的另一种简单方法是检查 AssignedLicenses
的计数,而不是检查它是否为空。
这个 属性 是一个数组,正如 juunas 提到的,这个 属性 不能为空。您可以参考下面的代码修改这段代码:
If (($ADUser.Enabled -eq $true) -and ($O365User.AssignedLicenses.Count -ne 0))
我正在尝试查找已分配特定许可类型的所有用户。 我基本上是在尝试将我的 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"
通过 Azure AD V2 PowerShell 检查用户是否拥有许可证的另一种简单方法是检查 AssignedLicenses
的计数,而不是检查它是否为空。
这个 属性 是一个数组,正如 juunas 提到的,这个 属性 不能为空。您可以参考下面的代码修改这段代码:
If (($ADUser.Enabled -eq $true) -and ($O365User.AssignedLicenses.Count -ne 0))