<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>change UserPrincipalName with Powershell Archives - the Sysadmin Channel</title>
	<atom:link href="https://thesysadminchannel.com/tag/change-userprincipalname-with-powershell/feed/" rel="self" type="application/rss+xml" />
	<link>https://thesysadminchannel.com/tag/change-userprincipalname-with-powershell/</link>
	<description>Documenting My Life as a System Administrator</description>
	<lastBuildDate>Tue, 09 Nov 2021 21:48:29 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>
<site xmlns="com-wordpress:feed-additions:1">144174110</site>	<item>
		<title>How To Change UserPrincipalName with PowerShell</title>
		<link>https://thesysadminchannel.com/change-userprincipalname-with-powershell/</link>
					<comments>https://thesysadminchannel.com/change-userprincipalname-with-powershell/#comments</comments>
		
		<dc:creator><![CDATA[Paul Contreras]]></dc:creator>
		<pubDate>Tue, 09 Nov 2021 21:48:29 +0000</pubDate>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[change upn with csv file]]></category>
		<category><![CDATA[change UserPrincipalName with Powershell]]></category>
		<category><![CDATA[set a UPN suffix in Active Directory]]></category>
		<category><![CDATA[set upn suffix bulk users]]></category>
		<guid isPermaLink="false">https://thesysadminchannel.com/?p=3511</guid>

					<description><![CDATA[<p>Imagine a scenario where you work for an organization that has just changed it name to something more user friendly. One of things that are asked of the SysAdmins is that they want to be able to change all UserPrincipalNames&#8230; <a href="https://thesysadminchannel.com/change-userprincipalname-with-powershell/" class="more-link">Continue Reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a href="https://thesysadminchannel.com/change-userprincipalname-with-powershell/">How To Change UserPrincipalName with PowerShell</a> appeared first on <a href="https://thesysadminchannel.com">the Sysadmin Channel</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Imagine a scenario where you work for an organization that has just changed it name to something more user friendly.  One of things that are asked of the SysAdmins is that they want to be able to change all UserPrincipalNames from the previous UPN Domain Suffix to the New UPN Suffix.  This article will focus on how to change UserPrincipalName with PowerShell.</p>
<div id="tableofcontents">
<h2>Table Of Contents</h2>
<ul>
<li><a href="#Requirements">Requirements</a></li>
<li><a href="#UPNSuffix">Add A New UPN Suffix to Active Directory</a></li>
<ul>
<li><a href="#DomainSuffix">Get Domain Suffixes Currently In AD</a></li>
</ul>
<li><a href="#SetUPN">Change UserPrincipalName with PowerShell</a></li>
<ul>
<li><a href="#SetUPNSingleUser">Set The UPN Suffix For A Single User</a></li>
<li><a href="#SetUPNBulkUser">Change The UserPrincipalName For Bulk Users</a></li>
<li><a href="#SetUPNFromCsv">Use PowerShell to Change UPN Suffix from Csv File</a></li>
</ul>
<li><a href="#Conclusion">Conclusion</a></li>
</ul>
</div>
<div id="Requirements" style="scroll-margin-top: 15px;"></div>
<h2>Requirements</h2>
<p>If you&#8217;re wanting to change the UPN suffix for your users there are a couple of things needed to make that happen.  Let&#8217;s list that down now.</p>
<ul>
<li>Permissions to modify AD Accounts</li>
<li>The UPN Suffix is added to your Domain</li>
</ul>
<div id="UPNSuffix" style="scroll-margin-top: 15px;"></div>
<h2>Add A New UPN Suffix to Active Directory</h2>
<p>As mentioned in one of the requirements, you&#8217;ll need to add the UPN suffix to be able to set it correctly.  Seems pretty obvious right! We&#8217;ll walk through how to do that.</p>
<ul>
<li>Open <strong>Active Directory Domain and Trusts</strong> console</li>
<li>Right click <strong>Active Directory Domain and Trusts</strong> -> <strong>Properties</strong></li>
<li><strong>Add the domain</strong> you would like to use</li>
</ul>
<p><a href="https://thesysadminchannel.com/wp-content/uploads/2021/11/Domain-and-Trust-Properties-Update.png" target="_blank" rel="noopener"><img fetchpriority="high" decoding="async" src="https://thesysadminchannel.com/wp-content/uploads/2021/11/Domain-and-Trust-Properties-Update.png" alt="Domain and Trust Properties" width="921" height="612" class="aligncenter size-full wp-image-3658" srcset="https://thesysadminchannel.com/wp-content/uploads/2021/11/Domain-and-Trust-Properties-Update.png?v=1636051214 921w, https://thesysadminchannel.com/wp-content/uploads/2021/11/Domain-and-Trust-Properties-Update-768x510.png?v=1636051214 768w" sizes="(max-width: 921px) 100vw, 921px" /></a></p>
<p>&nbsp;</p>
<p>As you can see from the screenshot above, I added the domain thesysadminchannel.com since this is what I want my users to login as. However, before we get to changing the UPN for our users, let&#8217;s first validate that the domain suffix is available and correctly added to Active Directory.</p>
<div id="DomainSuffix" style="scroll-margin-top: 15px;"></div>
<h3>Get Domain Suffixes Currently In AD</h3>
<p>As ironic as it seems, the Domains and Trust console is where we can confirm if the domain is added.  Nonetheless, we&#8217;ll take it a step further and verify this action dynamically using PowerShell.  This way if you want to automate your account creation, this will help get you started on the right track. Spoiler alert: This uses the <code>Get-ADForest</code> cmdlet.</p>
<pre class="brush: powershell; title: ; notranslate">
#Get UPN Suffix using Powershell
Get-ADForest | select UPNSuffixes
</pre>
<p><a href="https://thesysadminchannel.com/wp-content/uploads/2021/11/Get-ADForest-UPNSuffixes.png" target="_blank" rel="noopener"><img decoding="async" src="https://thesysadminchannel.com/wp-content/uploads/2021/11/Get-ADForest-UPNSuffixes.png" alt="Get-ADForest UPNSuffixes" width="900" height="300" class="aligncenter size-full wp-image-3660" srcset="https://thesysadminchannel.com/wp-content/uploads/2021/11/Get-ADForest-UPNSuffixes.png?v=1636052183 900w, https://thesysadminchannel.com/wp-content/uploads/2021/11/Get-ADForest-UPNSuffixes-768x256.png?v=1636052183 768w" sizes="(max-width: 900px) 100vw, 900px" /></a></p>
<p>&nbsp;</p>
<div id="SetUPN" style="scroll-margin-top: 15px;"></div>
<h2>Change UserPrincipalName with PowerShell</h2>
<p>Now for the bread and butter where we cover exactly how to change UserPrincipalName with PowerShell. We&#8217;ll go over multiple ways of setting the UPN suffix for a single user, multiple users in bulk or through a csv file that you can run the script against.  Seems to pretty awesome right?!?!</p>
<p>&nbsp;</p>
<div id="blockquote1">
<strong>Note:</strong> If you&#8217;re a Hybrid shop using Azure AD Connect, you&#8217;ll need to make sure your UPN Suffixes are using publicly routable domain names. Using a &#8220;.local&#8221; domain will use the tenant&#8217;s onmicrosoft.com domain as the UPN when it syncs to Azure Active Directory.
</div>
<p>&nbsp;</p>
<div id="SetUPNSingleUser" style="scroll-margin-top: 15px;"></div>
<h3>Set The UPN Suffix For A Single User</h3>
<p>In order to get an idea of how the change the UserPrincipalName, let&#8217;s run through an example of changing a single user that way you&#8217;re not overwhelmed right out of the gate. This article is primarily focused on doing it the &#8220;PowerShell&#8221; way, but sometimes it&#8217;s honestly a lot quicker to do it using the GUI if it&#8217;s just a one time thing.  No need to spend extra cycles. </p>
<ul>
<li>Open <strong>Active Directory Users and Computers</strong> (ADUC)</li>
<li><strong>Search the user</strong> and open <strong>properties</strong></li>
<li>Click on the <strong>Account tab</strong></li>
<li>Under <strong>User Logon Name</strong>, click the drop down to <strong>specify the UPN suffix</strong></li>
</ul>
<p><a href="https://thesysadminchannel.com/wp-content/uploads/2021/11/ADUC-Account-Properties-UPN-Suffix.png" target="_blank" rel="noopener"><img decoding="async" src="https://thesysadminchannel.com/wp-content/uploads/2021/11/ADUC-Account-Properties-UPN-Suffix.png" alt="ADUC Account Properties UPN Suffix - change UserPrincipalName with Powershell" width="850" height="510" class="aligncenter size-full wp-image-3667" srcset="https://thesysadminchannel.com/wp-content/uploads/2021/11/ADUC-Account-Properties-UPN-Suffix.png?v=1636074812 850w, https://thesysadminchannel.com/wp-content/uploads/2021/11/ADUC-Account-Properties-UPN-Suffix-125x75.png?v=1636074812 125w, https://thesysadminchannel.com/wp-content/uploads/2021/11/ADUC-Account-Properties-UPN-Suffix-768x461.png?v=1636074812 768w" sizes="(max-width: 850px) 100vw, 850px" /></a></p>
<p>&nbsp;</p>
<p>Ok now that we got that out of the way, let&#8217;s set ourselves up for success and essentially do the same thing using Powershell.</p>
<pre class="brush: powershell; title: ; notranslate">
#Change UPN for a single user using Powershell
$Domain = 'thesysadminchannel.com'
$User = 'ajolie'
Get-ADUser $User | select Name, UserPrincipalName

Name           UserPrincipalName
----           -----------------
Angelina Jolie ajolie@ad.thesysadminchannel.com


Get-ADUser $User | Set-ADUser -UserPrincipalName &quot;$user@$domain&quot;
Get-ADUser $User | select Name, UserPrincipalName

Name           UserPrincipalName
----           -----------------
Angelina Jolie ajolie@thesysadminchannel.com
</pre>
<p><a href="https://thesysadminchannel.com/wp-content/uploads/2021/11/Set-UPN-for-single-user-Powershell.png" target="_bank" rel="noopener"><img decoding="async" src="https://thesysadminchannel.com/wp-content/uploads/2021/11/Set-UPN-for-single-user-Powershell.png" alt="change UserPrincipalName with Powershell for single user" width="850" height="402" class="aligncenter size-full wp-image-3670" srcset="https://thesysadminchannel.com/wp-content/uploads/2021/11/Set-UPN-for-single-user-Powershell.png?v=1636416057 850w, https://thesysadminchannel.com/wp-content/uploads/2021/11/Set-UPN-for-single-user-Powershell-768x363.png?v=1636416057 768w" sizes="(max-width: 850px) 100vw, 850px" /></a></p>
<p>&nbsp;</p>
<div id="SetUPNBulkUser" style="scroll-margin-top: 15px;"></div>
<h3>Change The UserPrincipalName For Bulk Users</h3>
<p>Needing to be able to change a single user is great and all, however, what if we needed to change 1,000 users? 10,000 users in bulk?  As an exercise, we&#8217;ll change the UPN for all users in a specific OU.  This will allow us to see how to dynamically query AD users and modify their UPN without too much effort.</p>
<p>&nbsp;</p>
<p>As a reference point, we&#8217;ll use <a href="https://thesysadminchannel.com/get-aduser-find-active-directory-users-using-powershell-ultimate-deep-dive/#SearchBaseParameter" rel="noopener" target="_blank">Get-ADUser and filter by Organizational Unit</a> so we can scope the target base. Just for good measure, it&#8217;s always a good to take an export (backup) of the user&#8217;s current settings.  The <em>UserPrincipalName</em> is a primary attribute in Active Directory so at the very least, practice on a few test users or even a test Domain so you know exactly what the outcome is going to be.  Let&#8217;s get started.</p>
<pre class="brush: powershell; title: ; notranslate">
#Specify UPN Domain
$Domain = 'thesysadminchannel.com'

#Get list of samaccountnames in our targeted OU
$UserList = Get-ADUser -Filter * -SearchBase 'OU=Excluded,DC=ad,DC=thesysadminchannel,DC=com' | `
select -ExpandProperty SamAccountName

#Change UPN Suffix from sub domain to primary domain
foreach ($User in $UserList) {
    Get-ADUser $User | Set-ADUser -UserPrincipalName &quot;$User@$Domain&quot;
}

Get-ADUser -Filter * -SearchBase 'OU=Excluded,DC=ad,DC=thesysadminchannel,DC=com' | select Name, UserPrincipalName

Name               UserPrincipalName
----               -----------------
Isabella Contreras icontreras@thesysadminchannel.com
Director of IT     director1@thesysadminchannel.com
Arya Stark         astark@thesysadminchannel.com
Angelina Jolie     ajolie@thesysadminchannel.com
Melissa Zuniga     mzuniga@thesysadminchannel.com

</pre>
<p><a href="https://thesysadminchannel.com/wp-content/uploads/2021/11/Set-UPN-Suffix-for-bulk-users.png" target="_blank" rel="noopener"><img decoding="async" src="https://thesysadminchannel.com/wp-content/uploads/2021/11/Set-UPN-Suffix-for-bulk-users.png" alt="change UserPrincipalName with Powershell for bulk users" width="1111" height="489" class="aligncenter size-full wp-image-3675" srcset="https://thesysadminchannel.com/wp-content/uploads/2021/11/Set-UPN-Suffix-for-bulk-users.png?v=1636418746 1111w, https://thesysadminchannel.com/wp-content/uploads/2021/11/Set-UPN-Suffix-for-bulk-users-1024x451.png?v=1636418746 1024w, https://thesysadminchannel.com/wp-content/uploads/2021/11/Set-UPN-Suffix-for-bulk-users-768x338.png?v=1636418746 768w" sizes="(max-width: 1111px) 100vw, 1111px" /></a></p>
<p>&nbsp;</p>
<div id="SetUPNFromCsv" style="scroll-margin-top: 15px;"></div>
<h3>Use PowerShell to Change UPN Suffix from Csv File</h3>
<p>An alternative method to changing users in bulk is to use a csv.  You can format the csv anyway you want to but essentially we&#8217;re looking to import it and change the users based off of that. Let&#8217;s create  sample csv.  </p>
<p>The headers will be samaccountname,userprincipalname,name,enabled but we&#8217;ll mainly be relying on the samaccountname for out input.</p>
<p><a href="https://thesysadminchannel.com/wp-content/uploads/2021/11/csvfile.png" target="_blank" rel="noopener"><img decoding="async" src="https://thesysadminchannel.com/wp-content/uploads/2021/11/csvfile.png" alt="csvfile" width="857" height="288" class="aligncenter size-full wp-image-3679" srcset="https://thesysadminchannel.com/wp-content/uploads/2021/11/csvfile.png?v=1636477808 857w, https://thesysadminchannel.com/wp-content/uploads/2021/11/csvfile-768x258.png?v=1636477808 768w" sizes="(max-width: 857px) 100vw, 857px" /></a></p>
<p>&nbsp;</p>
<p>Here is the code to be able update that as we did in our previous steps.</p>
<pre class="brush: powershell; title: ; notranslate">
#Specify UPN Domain
$Domain = 'thesysadminchannel.com'

#Import csv to a csvList variable.
$csvList = Import-Csv 'C:\Users\pcontreras\csvList.csv'

#Change UPN Suffix from sub domain to primary domain using the csv file
foreach ($User in $csvList.samaccountname) {
    Get-ADUser $User | Set-ADUser -UserPrincipalName &quot;$User@$Domain&quot;
}
</pre>
<p><a href="https://thesysadminchannel.com/wp-content/uploads/2021/11/Set-UPN-Suffix-from-csv-file.png" target="_blank" rel="noopener"><img decoding="async" src="https://thesysadminchannel.com/wp-content/uploads/2021/11/Set-UPN-Suffix-from-csv-file.png" alt="Set UPN Suffix from csv file" width="949" height="500" class="aligncenter size-full wp-image-3681" srcset="https://thesysadminchannel.com/wp-content/uploads/2021/11/Set-UPN-Suffix-from-csv-file.png?v=1636479154 949w, https://thesysadminchannel.com/wp-content/uploads/2021/11/Set-UPN-Suffix-from-csv-file-768x405.png?v=1636479154 768w" sizes="(max-width: 949px) 100vw, 949px" /></a></p>
<p>&nbsp;</p>
<div id="Conclusion" style="scroll-margin-top: 15px;"></div>
<h2>Conclusion</h2>
<p>So hopefully this article was able to give you a pretty idea for being able to change UserPrincipalName with Powershell.  The ability to change a UPN suffix in Active Directory will definitely come in handy if you&#8217;re making changes to your org. </p>
<p>&nbsp;</p>
<p>As always, be sure to check out our other content full of Powershell Wizardry.  Articles such as <a href="https://thesysadminchannel.com/get-account-lock-out-source-powershell/" rel="noopener" target="_blank">Get Active Directory Account Lockout Source Using Powershell</a> or even our <a href="https://www.youtube.com/c/theSysadminChannel" rel="noopener" target="_blank">Youtube Channel</a> for amazing video content</p>
<p>The post <a href="https://thesysadminchannel.com/change-userprincipalname-with-powershell/">How To Change UserPrincipalName with PowerShell</a> appeared first on <a href="https://thesysadminchannel.com">the Sysadmin Channel</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://thesysadminchannel.com/change-userprincipalname-with-powershell/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3511</post-id>	</item>
	</channel>
</rss>
