我已经编写了一个 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 许可证吗?
Microsoft 于 2023 年 3 月 31 日停用了 Azure AD Graph 和 MSOnline PowerShell 许可分配 API 和 PowerShell cmdlet。链接
您现在必须使用 Microsoft Graph PowerShell 模块和 Set-MgUserLicense cmdlet。
• PowerShell {% if %} {% endif %} 语法抛出错误
• powershell gh 命令在运行 update-hlp 后失败
• Get-AzAccessToken 失败并出现错误“SharedTokenCacheCredential 身份验证不可用”
• Get-AzureADAuditSignInLogs 在自动化帐户中返回 $null
• 为什么 Visual Studio Code 不断加载 PowerShell 扩展?
• PowerShell 模块 SqlServer v21.1.18256 找不到 Get-SqlInstance cmdlet
• 尝试在 C# 中执行 Powershell 脚本时出现错误。对象引用未设置到对象的实例
• PowerShell Azure Function 导入模块错误
• Powershell:术语“powershell”未被识别为 cmdlet 的名称
• 在 Powershell 中解析 XML 并获取所有 xsd 验证错误
• Powershell:尝试从 WMIObject 查询返回特定值
• Install-Module:术语“Install-Module”未被识别为 cmdlet 的名称
• PowerShell 脚本错误:底层连接已关闭:无法为 SSL/TLS 安全通道建立信任关系