【发布时间】:2023-02-07 22:46:26
【问题描述】:
对于下面的这些 cmdlet,我尝试使用 [CmdletBinding(SupportsShouldProcess)] 行创建函数,但不确定它是否有效。
使用:https://learn.microsoft.com/en-us/powershell/module/msonline/set-msoluserlicense?view=azureadps-1.0
如何修改脚本以支持-WhatIf参数?
function Remove-License {
[CmdletBinding(SupportsShouldProcess)]
param ([String] $UserPrincipalName )
$AssignedLicense = (Get-MsolUser -UserPrincipalName $UserPrincipalName).licenses.AccountSkuId
$AssignedLicense |
ForEach-Object {
Write-Host "Removing $($UserPrincipalName) License $($AssignedLicense)..." -ForegroundColor Red
Set-MsolUserLicense -UserPrincipalName $upn -RemoveLicenses $_ -Verbose
}
}
Remove-License -UserPrincipalName 'User.Name@domain.com' -WhatIf
【问题讨论】:
标签: azure powershell azure-active-directory office365 azure-powershell