# Add a UPN

**URL:** <https://forums.powershell.org/t/add-a-upn/705>\
**Category:** PowerShell Help\
**Created:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/add-a-upn/705 "2011-12-31T18:30:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![archives](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@archives](https://forums.powershell.org/u/archives)\
**Post date:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/add-a-upn/705/1 "2011-12-31T18:30:00Z")

</div>

by NeatAccurateTypist at 2013-03-11 14:54:08

> I used Import-CSV to create a load of AD accounts today but forgot to add the UserPrincipalName property.  
>   
> I realise I should have added something like: -UserPrincipalName ($_.samAccountName + ‘@domain.com’) in my original command, but now I’m trying to add the UPN to the newly-created accounts._  
>   
> _I’m trying something along the lines of:_  
>   
> _Get-ADUser -filter \* -SearchBase ‘OU=OrganizationlUnit,DC=domain,DC=com’ | Set-ADUser -UserPrincipalName …_  
>   
> _What’s the equivalent of "($_.samAccountName + ‘@domain.com’)" for accounts that already exist, but have no UPN?  
>   
> Thanks.

by DonJ at 2013-03-13 08:00:25

> You need to chuck in a ForEach.  
>   
> Get-ADUser -filter \* | ForEach { Set-ADUser }  
>   
> Within the {} you’ll have $\_ again.

by NeatAccurateTypist at 2013-03-13 08:36:58

> Thanks I’ve tried this but I’m getting this reply:  
>   
> cmdlet Set-ADUser at command pipeline position 1

by DonJ at 2013-03-13 08:40:27

> Ok, so show me the exact command you tried to run that gave you that error.

by NeatAccurateTypist at 2013-03-13 09:00:31

> I’ve been trying a few things, with and without parentheses within the curly brackets, along the lines of:  
>   
> Get-ADUser -filter \* | ForEach { Set-ADUser -UserPrincipalName ($_.samAccountName + ‘@domain.com’) }_

_by MasterOfTheHat at 2013-03-13 09:36:08_

> _I don’t have a test domain to verify it on, but it should be as simple as:  
> `Get-ADUser -filter * | ForEach { Set-ADUser -UserPrincipalName "$($`_`.samAccountName + '@domain.com')" }`  
>   
> Note the quotes and extra $ in the -UserPrincipleName parameter…

by NeatAccurateTypist at 2013-03-13 09:47:57

> Thanks MasterOfTheHat,  
>   
> I’ve tried your suggestion, but I’m still getting the following message:  
>   
> cmdlet Set-ADUser at command pipeline position 1  
> Supply values for the following parameters:  
> Identity:

by MasterOfTheHat at 2013-03-13 10:45:18

> AH! Makes sense… The Set-ADUser command doesn’t know what user object to apply the UPN to! Sorry I forgot that. Try:  
> `Get-ADUser -filter * | ForEach { Set-ADUser -Identity "$.samAccountName" -UserPrincipalName "$($.samAccountName + '@domain.com')" }`

by NeatAccurateTypist at 2013-03-14 05:57:20

> Thanks MasterofTheHat!  
>   
> I tried that and it needed a slight adjustment (I had to remove the quotes from around the first "$\_.samAccountName" and then it ran perfectly).  
>   
> Did exactly what I needed! Thanks again!  
>   
> 🙂

---

<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:58pm UTC](https://forums.powershell.org/t/add-a-upn/705/2 "2024-05-16T20:58:31Z")

</div>


