{"id":4743,"date":"2012-11-01T00:01:00","date_gmt":"2012-11-01T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2012\/11\/01\/use-powershell-to-standardize-titles-in-active-directory\/"},"modified":"2012-11-01T00:01:00","modified_gmt":"2012-11-01T00:01:00","slug":"use-powershell-to-standardize-titles-in-active-directory","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-standardize-titles-in-active-directory\/","title":{"rendered":"Use PowerShell to Standardize Titles in Active Directory"},"content":{"rendered":"<p><b>Summary:<\/b> Microsoft Scripting Guy, Ed Wilson, shows how to use Windows PowerShell to standardize user titles and descriptions in Active Directory Domain Services (AD&nbsp;DS).\nMicrosoft Scripting Guy, Ed Wilson, is here. Well, the weather in Charlotte, North Carolina, has certainly turned&mdash;it&rsquo;s cold outside, gray, and our friends just a few miles north of us are shoveling snow. Some of this is the aftermath of Hurricane Sandy I imagine, but then I only had one course in weather-guessing at the university, so I am not really qualified to say.\nTonight, the <a href=\"http:\/\/powershellgroup.org\/charlotte.nc\">Charlotte Windows PowerShell user group meets at the Microsoft office<\/a>, and the Scripting Wife is chomping at the bit to head out armed with her new Windows Surface. It does have Windows PowerShell on it, so it is an appropriate device to take to the group meetings. You can still sign up for the meeting if you happen to be in the area. We will have a mini Scripting Games event planned, and it will be a blast!\nI am qualified to say that Windows PowerShell&nbsp;3.0 absolutely rocks, and, yet, what I am doing today is basically the same as what would be accomplished with Windows PowerShell&nbsp;2.0.<\/p>\n<p style=\"padding-left: 30px\"><b>Note<\/b> &nbsp;&nbsp;This is the third in a series of posts about creating a test Active Directory environment. On Tuesday, I began the series with the <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2012\/10\/30\/create-test-users-in-a-test-active-directory-environment-by-using-powershell.aspx\" target=\"_blank\">Create Test Users in a Test Active Directory Environment by Using PowerShell<\/a> post, where I wrote a script to create a test organizational unit with 100 test user accounts. On Wednesday, I wrote <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2012\/10\/31\/use-powershell-to-modify-existing-user-accounts-in-active-directory.aspx\" target=\"_blank\">Use PowerShell to Modify Existing User Accounts in Active Directory<\/a>, where I talked about using existing user information to create new information such as email addresses and personal web page URLs. You should refer to those articles prior to reading today&rsquo;s article.<\/p>\n<h2>Finding and correcting wayward job titles in AD&nbsp;DS<\/h2>\n<p>One of the great things about storing user information in Active Directory Domain Services (AD&nbsp;DS) is that it becomes a centralized repository of user information. The problem is that if you search for a &ldquo;Senior Network Engineer&rdquo; in the Global Address List in Outlook and some folks have the title &ldquo;Sr. Network Engineer,&rdquo; then the search fails to find some of the engineers.\n<a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2012\/10\/30\/create-test-users-in-a-test-active-directory-environment-by-using-powershell.aspx\" target=\"_blank\">Tuesday&rsquo;s blog article<\/a> described the situation in great detail, and I spent the last couple of days setting up a test environment. Today, I will search a particular organizational unit in the test domain for the following permutations of the Senior Network Engineer job title, and I will change them all to read as &ldquo;Senior Network Engineer.&rdquo; The different ways of expressing the title appear here.<\/p>\n<p style=\"padding-left: 30px\">&nbsp;Sr. NetEng<\/p>\n<p style=\"padding-left: 30px\">&nbsp;SR. NetEng<\/p>\n<p style=\"padding-left: 30px\">&nbsp;Senior NetEng<\/p>\n<p style=\"padding-left: 30px\">&nbsp;Sr. Network Engineer<\/p>\n<p style=\"padding-left: 30px\">&nbsp;sr. network engineer<\/p>\n<p style=\"padding-left: 30px\">&nbsp;sr. neteng<\/p>\n<p style=\"padding-left: 30px\">&nbsp;Senior Network Engineer<\/p>\n<p style=\"padding-left: 30px\">&nbsp;Sr. Net Eng<\/p>\n<p style=\"padding-left: 30px\">&nbsp;SR NET ENG<\/p>\n<p style=\"padding-left: 30px\">&nbsp;SR. NETENG\nTo ensure that you have complete coverage of the different ways the title is expressed, use the <b>Get-ADUser<\/b> cmdlet to search the desired organizational unit and group the titles. A command that accomplishes this is shown here. I will also use this command following the modifications to ensure the script works as required.<\/p>\n<p style=\"padding-left: 30px\">PS C:&gt; Get-ADUser -SearchBase &#8216;ou=testou,dc=iammred,dc=net&#8217; -Filter * -Properties title | group title -NoElement<\/p>\n<p style=\"padding-left: 30px\">&nbsp;Count Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<\/p>\n<p style=\"padding-left: 30px\">&#8212;&#8211; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; 11 Senior NetEng&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; 39 SR. NETENG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; 6 Senior Network Engineer&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; 17 Sr. Net Eng&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; 23 Sr. Network Engineer&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; 4 SR NET ENG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\nI create a $title variable and assign an array of inconsistent titles I discovered from running the previous command. I do not add the Senior Network Engineer title to the array because there is no need to change it for the six instances it already occurs in the Active Directory. Here is the array I use.<\/p>\n<p style=\"padding-left: 30px\">$title = @(<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&#8216;Sr. NetEng&#8217;,<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&#8216;SR. NetEng&#8217;,<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&#8216;Senior NetEng&#8217;,<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&#8216;Sr. Network Engineer&#8217;,<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&#8216;sr. network engineer&#8217;,<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&#8216;sr. neteng&#8217;,<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&#8216;Sr. Net Eng&#8217;,<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&#8216;SR NET ENG&#8217;,<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&#8216;SR. NETENG&#8217;)\nNext, I create a variable to hold the new title I will use. This new title is &ldquo;Senior Network Engineer<i>.<\/i>&rdquo;<i> <\/i>The variable and value assignment is shown here.<\/p>\n<p style=\"padding-left: 30px\">$newtitle = &#8216;Senior Network Engineer&#8217;\nNow, I import the Active Directory module, and I use the <b>Get-ADUser<\/b> cmdlet to search the organizational unit containing the users that have the inconsistent titles. I use a wildcard for the filter, and specifically choose the <b>Title<\/b> and the <b>Description<\/b> properties to return with the search results. This portion of the script is shown here.<\/p>\n<p style=\"padding-left: 30px\">Get-ADUser -SearchBase &#8216;ou=testou,dc=iammred,dc=net&#8217; -Filter * `<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; -Properties Title, Description\nThe returned user objects are piped to the <b>Foreach-Object<\/b> cmdlet. In <b>process scriptblock<\/b><i> <\/i>of the <b>Foreach-Object<\/b> cmdlet (<b>process<\/b><i> <\/i>is the default parameter of the <b>Foreach-Object<\/b> cmdlet and is commonly omitted from the command itself), I use the <b>if <\/b>statement to see if the array of inconsistent titles contains the current user&#8217;s title. The <b>contains<\/b><i> <\/i>operator is case-insensitive and will, therefore, match both Sr NetEng as well as SR NETENG. What would not be matched is SENIOR NETWORK ENGINEER, but my previous command revealed that was not a possibility, and, therefore, I decided to do a case-insensitive search instead of a case-sensitive search. This portion of the code is shown here.<\/p>\n<p style=\"padding-left: 30px\">Foreach-Object {<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; if ($title -contains $_.title)&nbsp;\nIf a match occurs, I use the <b>Set-ADUser<\/b> cmdlet to assign the new title stored in the <b>$newtitle<\/b> variable to both the <b>title<\/b><i> <\/i>and to the <b>description<\/b><i> <\/i>attributes in Active Directory. Luckily, both of these attributes are settable through a direct parameter, and, therefore, the process is simple. This line of code is shown here.<\/p>\n<p style=\"padding-left: 30px\">Set-ADUser -identity $_ -Title $newtitle -Description $newtitle\nThe complete SetStandardADTitle.ps1 script is shown here.<\/p>\n<p style=\"padding-left: 30px\"># &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p style=\"padding-left: 30px\"># Script: SetStandardADTitle.ps1<\/p>\n<p style=\"padding-left: 30px\"># Author: ed wilson, msft<\/p>\n<p style=\"padding-left: 30px\"># Date: 10\/30\/2012 11:54:48<\/p>\n<p style=\"padding-left: 30px\"># Keywords: Active Directory, User Accounts<\/p>\n<p style=\"padding-left: 30px\"># comments:<\/p>\n<p style=\"padding-left: 30px\"># HSG-11-1-2012<\/p>\n<p style=\"padding-left: 30px\"># &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p style=\"padding-left: 30px\">$title = @(<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&#8216;Sr. NetEng&#8217;,<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&#8216;SR. NetEng&#8217;,<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&#8216;Senior NetEng&#8217;,<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&#8216;Sr. Network Engineer&#8217;,<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&#8216;sr. network engineer&#8217;,<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&#8216;sr. neteng&#8217;,<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&#8216;Sr. Net Eng&#8217;,<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&#8216;SR NET ENG&#8217;,<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&#8216;SR. NETENG&#8217;)<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">$newtitle = &#8216;Senior Network Engineer&#8217;<\/p>\n<p style=\"padding-left: 30px\">Import-Module ActiveDirectory<\/p>\n<p style=\"padding-left: 30px\">Get-ADUser -SearchBase &#8216;ou=testou,dc=iammred,dc=net&#8217; -Filter * `<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; -Properties Title, Description |<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; Foreach-Object {<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp; if ($title -contains $_.title)<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set-ADUser -identity $_ -Title $newtitle -Description $newtitle<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; }\nFinally, I use the up arrow from the Windows PowerShell ISE command\/output window to recall my previous command and ensure the script worked as desired.<\/p>\n<p style=\"padding-left: 30px\">PS C:&gt; Get-ADUser -SearchBase &#8216;ou=testou,dc=iammred,dc=net&#8217; -Filter * -Properties title | group title -NoElement<\/p>\n<p style=\"padding-left: 30px\">Count Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&#8212;&#8211; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp; 100 Senior Network Engineer&nbsp;\nI see it worked. Cool &hellip;\nActive Directory week will continue tomorrow when I will talk about setting user location information with Windows PowerShell.\nI invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.\n<b>Ed Wilson, Microsoft Scripting Guy<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, shows how to use Windows PowerShell to standardize user titles and descriptions in Active Directory Domain Services (AD&nbsp;DS). Microsoft Scripting Guy, Ed Wilson, is here. Well, the weather in Charlotte, North Carolina, has certainly turned&mdash;it&rsquo;s cold outside, gray, and our friends just a few miles north of us are [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[7,3,20,45],"class_list":["post-4743","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-scripting-guy","tag-user-accounts","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, shows how to use Windows PowerShell to standardize user titles and descriptions in Active Directory Domain Services (AD&nbsp;DS). Microsoft Scripting Guy, Ed Wilson, is here. Well, the weather in Charlotte, North Carolina, has certainly turned&mdash;it&rsquo;s cold outside, gray, and our friends just a few miles north of us are [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4743","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=4743"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4743\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=4743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=4743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=4743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}