# Bulk change user password for AzureAD users

**URL:** <https://forums.powershell.org/t/bulk-change-user-password-for-azuread-users/19067>\
**Category:** PowerShell Help\
**Created:** [April 12, 2022, 2:49pm UTC](https://forums.powershell.org/t/bulk-change-user-password-for-azuread-users/19067 "2022-04-12T14:49:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arek](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@Arek](https://forums.powershell.org/u/Arek)\
**Post date:** [April 12, 2022, 2:49pm UTC](https://forums.powershell.org/t/bulk-change-user-password-for-azuread-users/19067/1 "2022-04-12T14:49:00Z")

</div>

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:

```auto
'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.

Thanks
Arek
```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [April 12, 2022, 3:29pm UTC](https://forums.powershell.org/t/bulk-change-user-password-for-azuread-users/19067/2 "2022-04-12T15:29:36Z")

</div>

Arek,  
Welcome to the forum. 👋🏽

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:

```auto
$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.

---

<div class="post-metadata">

**Author:** ![Arek](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@Arek](https://forums.powershell.org/u/Arek)\
**Post date:** [April 20, 2022, 4:22pm UTC](https://forums.powershell.org/t/bulk-change-user-password-for-azuread-users/19067/3 "2022-04-20T16:22:27Z")

</div>

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.

Arek

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:18pm UTC](https://forums.powershell.org/t/bulk-change-user-password-for-azuread-users/19067/4 "2024-05-16T20:18:01Z")

</div>

Closed on May 16, 2024, 8:18pm UTC


