Thursday, July 19, 2018

Modifying User Principal Names suffixes in Active Directory


Recently I was asked to make mass changes to our AD environment which always makes me a little uneasy.  I do not "enjoy" making mass changes manually either, so I decided to use PowerShell to partially automate some of the process.

First things, first I you do not have Remote Server Administration Tools installed for you OS you will need to grab them here:

Remote Server Administration Tools for Windows 10


Instructions can be found for installation on the respective pages.  


After the installation of RSAT, I used Powershell ISE to create a script to export users to a text file.  There are several ways to go about doing this as a quick Google  search will reveal. 

The script below is simple but accomplished exactly what I needed while giving me some control/visibility over the process until I was sure that it was working as intended. 

Script below:

Import-Module ActiveDirectory  

# Imports Active Directory module for Powershell

$oldSuffix = "currentupnsuffix"

# Place current UPN suffix here in quotes everything to the right of the @ symbol ex. domain.com

$newSuffix = "newupnsuffix"

# Place new UPN suffix here in quotes - everything to the right of the @ symbol ex. @newdomain.com

Get-Content "export.txt" | Get-ADUser | ForEach-Object {

$newUpn = $_.UserPrincipalName.Replace($oldSuffix,$newSuffix)

$_ | Set-ADUser -UserPrincipalName $newUpn

}

#This block of code reads the file named export.txt (created from above) containing users samaccountnames.  Each time it finds a matching  UPN suffix, it replaces it with the new one.

**Disclaimer please remove the comments in red from the code before running the script. I did not test with the code with the comments added.

If you are unsure about this process, start by creating a test account and adding the samaccountname attribute value to a test text file. Run the script against the "test" account and determine if the scripts yields the desired outcome.

Sit back and enjoy the day!

Fixing Event ID 1085 - Group Policy Zonemapping


Event ID 1085 - Group Policy Zonemapping - Warning


Log Name: System
Source: Microsoft-Windows-GroupPolicy
Event ID: 1085
Level: Warning
Description: Windows failed to apply the Internet Explorer Zonemapping settings. Internet Explorer Zonemapping settings might have its own log file. Please click on the "More information" link.

Event ID 1085 - ZoneMapping


This is caused by invalid syntax in the GPO for site to zone assignments. Some of the exact causes of this warning can be found here:

https://blogs.msdn.microsoft.com/askie/2016/04/05/description-of-event-id-1085-from-internet-explorer-zonemapping/

*Note this policy exists under both Users and Computers configurations in Group Policy...be sure to check both places.

Troubleshooting this list is made a lot easier with the help of this tool:

https://blogs.msdn.microsoft.com/askie/2017/07/05/event-id-1085-from-internet-explorer-zonemapping-part-2-zonemap-troubleshoot-tool/


The tool can be run from any computer that contains this warning and will identify the incorrect entries in the list. Great time saver!