{"id":8488,"date":"2024-12-21T23:06:58","date_gmt":"2024-12-21T23:06:58","guid":{"rendered":"https:\/\/pariswells.com\/blog\/?p=8488"},"modified":"2024-12-21T23:06:59","modified_gmt":"2024-12-21T23:06:59","slug":"bulk-change-upn-for-users-to-onmicrosoft-com-for-domain-renewal-via-powershell-for-cloud-only-users-in-azure-ad","status":"publish","type":"post","link":"https:\/\/pariswells.com\/blog\/research\/bulk-change-upn-for-users-to-onmicrosoft-com-for-domain-renewal-via-powershell-for-cloud-only-users-in-azure-ad","title":{"rendered":"Bulk Change UPN for Users to .onmicrosoft.com for Domain Renewal via Powershell for Cloud only Users in Azure AD"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code class=\"\">Connect-AzureAD\n\n# Define old and new domains\n$oldDomain = \"domain.com.au\"\n$newDomain = \"cfch2020.onmicrosoft.com\"\n\n# Get all users with the old domain in their UPN\n$users = Get-AzureADUser -All $true | Where-Object { $_.UserPrincipalName -like \"*@$oldDomain\" }\n\nforeach ($user in $users) {\n    # Construct the new UPN\n    $newUPN = $user.UserPrincipalName -replace \"@$oldDomain\", \"@$newDomain\"\n\n    # Update the user's UPN\n    Write-Host \"Updating UPN for $($user.UserPrincipalName) to $newUPN\"\n    Set-AzureADUser -ObjectId $user.ObjectId -UserPrincipalName $newUPN\n}\n\nWrite-Host \"UPN update completed.\"<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8488","post","type-post","status-publish","format-standard","hentry","category-research"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/8488","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/comments?post=8488"}],"version-history":[{"count":1,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/8488\/revisions"}],"predecessor-version":[{"id":8489,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/8488\/revisions\/8489"}],"wp:attachment":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/media?parent=8488"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/categories?post=8488"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/tags?post=8488"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}