MSOnline PowerShell 错误“Get-MsolUserLicense”

问题描述 投票:0回答:1

我已经编写了一个 powershell 脚本,但出现以下错误:

The term 'Get-MsolUserLicense' is not recognized as the name of a cmdlet

已安装 MSOnline 模块。

 #Script to change users password, inbox to shared mailbox and remove any active licenses

if (Get-Module -ListAvailable -Name ExchangeOnlineManagement) {
    Write-Host " Exchange Module exists"

} 
else {
    Write-Host "Exchange Module does not exist. Installing now"
    Install-Module -Name ExchangeOnlineManagement
}
if (Get-Module -ListAvailable -Name MSOnline) {
    Write-Host "MS Online Module exists"

} 
else {
    Write-Host "Exchange Module does not exist. Installing now"
    Install-Module -Name MSOnline
}
$User = Read-Host -Prompt 'Input the user name'
$password = Read-Host -Prompt 'Enter random password'
Try {
    
    Connect-MsolService
    Connect-ExchangeOnline
    Set-MsolUserPassword -UserPrincipalName $User -NewPassword $password
    Get-DistributionGroup | Where-Object { (Get-DistributionGroupMember $_).PrimarySmtpAddress -contains $userEmail } | ForEach-Object { Remove-DistributionGroupMember -Identity $_.Name -Member $userEmail -Confirm:$false }
    Set-Mailbox -Identity $User -Type Shared

    # Remove all licenses from the user
    $licenses = Get-MsolUserLicense -UserPrincipalName $User
    Set-MsolUserLicense -UserPrincipalName $User -RemoveLicenses $licenses.AccountSkuId
}
Catch {
    write-host -f Red "Error:" $_.Exception.Message
} 

还有其他方法可以使用 PS 删除用户 365 许可证吗?

powershell microsoft365
1个回答
0
投票

Microsoft 于 2023 年 3 月 31 日停用了 Azure AD Graph 和 MSOnline PowerShell 许可分配 API 和 PowerShell cmdlet。链接

您现在必须使用 Microsoft Graph PowerShell 模块和 Set-MgUserLicense cmdlet。

© www.soinside.com 2019 - 2024. All rights reserved.