tabush
asked on
Change UPN Script
I need to change the UPN suffix for my entire domain. I found some scripts online but cannot get any of them to work. This is the powershell i tried. I cannot see the error either because powershell window doesnt stay open.
Import-Module ActiveDirectory
Get-ADUser -Filter {UserPrincipalName -like "*@DOMAIN.LOCAL"} -SearchBase "OU=Test,DC=TABUSH,DC=LOCA L" |
ForEach-Object {
$UPN = $_.DOMAIN.LOCAL,domain.com
Set-ADUser $_ -UserPrincipalName $UPN
}
Import-Module ActiveDirectory
Get-ADUser -Filter {UserPrincipalName -like "*@DOMAIN.LOCAL"} -SearchBase "OU=Test,DC=TABUSH,DC=LOCA
ForEach-Object {
$UPN = $_.DOMAIN.LOCAL,domain.com
Set-ADUser $_ -UserPrincipalName $UPN
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tried to use this powershell script and didnt work (UPN didnt change). I was careful in replacing the variables and was case sensitive just in case.
Is there any way to pause the script at the end so i can see if there are any errors? I am running the powershell by pasting this script into a .ps1 file then right clicking, run with powershell.
Is there any way to pause the script at the end so i can see if there are any errors? I am running the powershell by pasting this script into a .ps1 file then right clicking, run with powershell.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Think its something with the domain i was testing on. I was testing on windows 2008r2 server and it wasnt working then tried on another domain which has windows 2012 and it worked.
I noticed that powershell ISE wasnt installed on the 2008r2 server (not default on 2008r2). Ill add it to see if that has anything to do with script not working.
I noticed that powershell ISE wasnt installed on the 2008r2 server (not default on 2008r2). Ill add it to see if that has anything to do with script not working.
Having the ISE will not matter. If you are running this script in the Powershell native session when you need to copy the entire script into notepad and save it as a .ps1 file entension.
You cannot copy and paste what i have created into a powershell window. If you want to do it that way then you will have to use the ISE.
Will.
You cannot copy and paste what i have created into a powershell window. If you want to do it that way then you will have to use the ISE.
Will.
ASKER
Yes i was pasting into notepad, not powershell window.
When i ran on my 2012 server the first time a got a confirmation message within ISE to allow unsecure scripts to run and i had to type "Y"
Then after that i was able to run the script without confirmation. Maybe this is happening on 2008r2 but not giving me the option to type Y because i dont have ISE
When i ran on my 2012 server the first time a got a confirmation message within ISE to allow unsecure scripts to run and i had to type "Y"
Then after that i was able to run the script without confirmation. Maybe this is happening on 2008r2 but not giving me the option to type Y because i dont have ISE
That is your ExecutionPolicy.
You should set it to Set-ExecutionPolicy RemoteSigned
Will.
You should set it to Set-ExecutionPolicy RemoteSigned
Will.
ASKER
Thanks! Script works now
ASKER