简体   繁体   中英

How to disable Azure AD user reading UPN from a CSV file

I have around 100 UPN ( User Principle Name) in a excel file. This check user link says about the best practice. This link says how to remove. However, I need to disable 1st. and does not have exact info. Is there any ways to bulk disable ( NOT DELETE) all 100 accounts from Azure AD? from Azure portal or power automate or by using PowerShell Script?

Edit

This code: seems for AD not for AAD.

Import-Module ActiveDirectory
Import-Csv "C:\ScriptsUsers.csv" | ForEach-Object {
 $samAccountName = $_."samAccountName" 
 Get-ADUser -Identity $samAccountName | Disable-ADAccount
 }

Is there similar script available for Azure AD?

Modification for Azure AD

Import-Csv "D:\PowerShell\ScriptsUsers.csv" |
ForEach-Object {

Set-AzureADUser -ObjectID Userprincipalname -AccountEnabled $false
 }

However, the error shows:

Resource 'Userprincipalname' does not exists or one of its required reference properties object are not present

What Am I doing wrong? Thanks.

Depending on your csv file you need to change Userprincipalname to $($_.CSVattribute)

Import-Csv "D:\PowerShell\ScriptsUsers.csv" | ForEach-Object {
  Set-AzureADUser -ObjectId $($_.ObjectId) -AccountEnabled $false
}

or

Import-Csv "D:\PowerShell\ScriptsUsers.csv" | ForEach-Object {
    Set-AzureADUser -ObjectId $($_.Userprincipalname) -AccountEnabled $false
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM