Bulk change user password for AzureAD users

Hello All,
I have a generic users accounts that needs to have their password changed occasionally. I have been trying to resolve it with Powershell however I stuck on one particular problem.
All the users names have similar pattern which suppose to ease the pain.
Anyway, there is my code so far…
If anyone could shed some light I’d be very grateful.
Thanks in advance

’ $objectid = @(get-azureaduser -all $true | Where-Object {$_.userprincipalname -like “prorel*”} | select objectid)

foreach ($i in $objectid){
Set-AzureADUserPassword -ObjectId $i -password (convertto-securestring “Passwords2022” -AsPlainText -Force)

I’m receiving the following error message:

'Set-AzureADUserPassword : Error occurred while executing SetUser 
Code: Request_ResourceNotFound
Message: Resource '@{ObjectId=badd5c83-7f61-48a4-b475-37154dc17886}' does not exist or one of its queried reference-property objects are not present.
RequestId: 04979a93-8672-4f47-bb8e-3f2ca70d643d
DateTimeStamp: Tue, 12 Apr 2022 14:01:12 GMT
HttpStatusCode: NotFound
HttpStatusDescription: Not Found
HttpResponseStatus: Completed
At line:6 char:2
+  Set-AzureADUserPassword -ObjectId $i -password (convertto-securestri ...
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-AzureADUserPassword], ApiException
    + FullyQualifiedErrorId : Microsoft.Open.AzureAD16.Client.ApiException,Microsoft.Open.AzureAD16.Graph.PowerShell.Custom.Cmdlet.SetUserPassword'

I'm welcoming all suggestions.


Welcome to the forum. :wave:t4:

In POwerShell we work with objects and properties. So if you have an object and you want to access a particular property og this object you can use the dot notation.

The property in your case is ObjectID. Try this:

$AzureADUserList = Get-AzureADUser -All $true | Where-Object { $_.userprincipalname -like 'prorel*' } 
foreach ($AzureADUser in $AzureADUserList ) {
    Set-AzureADUserPassword -ObjectId $($AzureADUser.ObjectID) -Password (convertto-securestring 'Passwords2022' -AsPlainText -Force)

And BTW: are you really setting the passwords of all these users to the same password? That sounds like a really bad idea somehow.

Hi Olaf,
Thank you very much for your help. Everything works.

Setting the same password for multiple users doesn’t make sense for many reasons but my users are only temporary ones. I need them for few hour to few days and this is one of the reasons why I need to changed their passwords asap.

Thanks again for all your help.