# Gỡ license cho hàng loạt username từ file csv, có 1 cột UserToDisable
$csvPath = "D:\OneDrive\Downloads\Documents\ReportM365\UserToDisable.csv"
$users = Import-Csv $csvPath
$domain = "@tamanhhospital.vn"
# License cần remove
$targetLicenses = @(
"4b585984-651b-448a-9e53-3b10f069cf7f", # Microsoft 365 F3
"f8ced641-8e17-4dc5-b014-f5a2d53f6ac8", # Office 365 E1
"46c3a859-c90d-40b3-9551-6178a48d5c18", # Office 365 E3
"3ab6abff-666f-4424-bfb7-f0bc274ec7bc", # Microsoft Teams Essentials
"7e31c0d9-9551-471d-836f-32ee72be4a01" # Microsoft Teams Enterprise (Teams add-on)
)
foreach ($user in $users) {
try {
# Ghép domain vào username
$userId = $user.UserToDisable.Trim() + $domain
# Get license hiện tại
$currentLicenses = (Get-MgUser -UserId $userId -Property AssignedLicenses).AssignedLicenses.SkuId
# Lọc license cần remove
$removeLicenses = $targetLicenses | Where-Object { $_ -in $currentLicenses }
if ($removeLicenses.Count -gt 0) {
Set-MgUserLicense -UserId $userId -AddLicenses @() -RemoveLicenses $removeLicenses
Write-Host "$userId - Removed license" -ForegroundColor Green
}
else {
Write-Host "$userId - No target license" -ForegroundColor Yellow
}
}
catch {
Write-Host "$($user.UserToDisable) - ERROR: $($_.Exception.Message)" -ForegroundColor Red
}
}
Gỡ license 365 cho hàng loạt username
Subscribe to:
Post Comments (Atom)
Gỡ license 365 cho hàng loạt username
# Gỡ license cho hàng loạt username từ file csv, có 1 cột UserToDisable $csvPath = "D:\OneDrive\Downloads\Documents\ReportM365\UserToD...
-
Mở sysdm.cpl Xóa hết các user dưới 300MB, trừ Administrator và Default Profile Mở regedit: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows N...
-
Máy giặt cửa ngang LG dùng được khoảng 2,5 năm thì vỡ chốt khi mở cửa. Sau khi vỡ, các mảnh vỡ nằm lại trong hốc khóa, khá khó gắp. Các mảnh...
-
Tải bộ cài Windows 10 version 20H2 bằng Media Creation Tool, tách lấy file install.esd trong thư mục sources : Mount file ISO vào ổ ảo ...
No comments:
Post a Comment