如何通过输入文件使用 M365 中的脚本获取 Powershell 脚本来阻止用户登录并删除许可证并将用户邮箱转换为共享邮箱并将共享邮箱分配给其他人?
我尝试了下面的脚本,但它没有从输入 csv 文件中删除用户的许可证
# Define the path to the CSV file containing user email IDs
$inputFilePath = "C:\FolderName\FileName.csv"
# Read the CSV file
$userList = Import-Csv -Path $inputFilePath
foreach ($user in $userList) {
$userEmail = $user.Email
# Block user sign-in
Set-AzureADUser -ObjectId (Get-AzureADUser -Filter "UserPrincipalName eq '$userEmail'").ObjectId -AccountEnabled $false
# Remove licenses for the user
Set-AzureADUserLicense -ObjectId (Get-AzureADUser -ObjectId $userEmail).ObjectId -RemoveLicenses "DEVELOPERPACK_E5"
# Convert mailbox to shared mailbox
Set-Mailbox -Identity $userEmail -Type Shared
Add-MailboxPermission -Identity $userEmail -User $Delegates -AccessRights FullAccess
}
仅适用于登录阻止并将邮箱从用户邮箱转换为共享邮箱
但我的要求是登录阻止,删除许可证,将邮箱从用户邮箱转换为共享邮箱,并将共享邮箱分配给其他人作为具有完全权限的代表。
为了删除 O365 中的许可证,我假设您正在尝试执行此操作,我使用了命令
Set-MsolUserLicense -UserPrincipalName $Username -RemoveLicenses $License
您可以通过 Connect-MsolService 进行连接,您可以将用户凭据传递到其中,适用于我的用户 decomm 脚本。