简体   繁体   English

O365,AD和Powershell - 尝试在OU中查找许可用户

[英]O365, AD & Powershell - Trying to find licensed users in OU

I am currently on the lookout for unused O365 licenses, previously I have used this code to find somewhat of a goldmine: 我目前正在寻找未使用的O365许可证,之前我使用此代码来查找某种金矿:

$cred=Get-Credential $o365account
Connect-MsolService -Credential $cred
Get-MsolUser -All | where {$_.isLicensed -eq $true -and $_.BlockCredential -eq $true} | Select UserPrincipalName, MSExchRecipientTypeDetails | Export-Csv -Path “C:\Users\xalaals\Desktop\O365Licensed_ADDisabledUsers_2.txt” -NoTypeInformation

Now we have an OU in AD with a bunch of users that are inactive (disabled & enabled accounts), so my question would be if it is possible to repurpose the above code to find O365 licenses on BOTH enabled and disabled accounts within said OU? 现在我们在AD中有一个OU,其中有一堆用户处于非活动状态(禁用和启用帐户),所以我的问题是,是否可以重新调整上述代码,以便在所述OU中启用和禁用BOTH的帐户中找到O365许可证?

You can first get list of all users from the OU you mentioned: 您可以先从您提到的OU中获取所有用户的列表:

get-aduser -SearchBase "OU=St. Petersburg,ou=Users,OU=Orc,DC=ad,DC=*****,DC=com" -filter * | Select -ExpandProperty Userprincipalname

then pass those users to Get-MsolUser cmdlet and use foreach 然后将这些用户传递给Get-MsolUser cmdlet并使用foreach

(Get-ADUser -SearchBase "OU=St. Petersburg,ou=Users,OU=Orc,DC=ad,DC=*****,DC=com" -filter * | Select -ExpandProperty Userprincipalname) | %{Get-MsolUser -UserPrincipalName $_ -erroraction silentlycontinue| where {$_.isLicensed -eq $true -and $_.BlockCredential -eq $true} | Select UserPrincipalName, MSExchRecipientTypeDetails} | Export-Csv -Path “C:\Users\xalaals\Desktop\O365Licensed_ADDisabledUsers_2.txt” -NoTypeInformation

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

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