{"id":16821,"date":"2010-10-14T00:01:00","date_gmt":"2010-10-14T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2010\/10\/14\/use-powershell-and-active-directory-cmdlets-to-update-users-in-active-directory\/"},"modified":"2010-10-14T00:01:00","modified_gmt":"2010-10-14T00:01:00","slug":"use-powershell-and-active-directory-cmdlets-to-update-users-in-active-directory","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-and-active-directory-cmdlets-to-update-users-in-active-directory\/","title":{"rendered":"Use PowerShell and Active Directory Cmdlets to Update Users in Active Directory"},"content":{"rendered":"<p><span><span style=\"font-family: Arial\"><span style=\"font-size: 10pt;color: #000000\"><strong><\/strong><\/span><\/span><\/span><\/p>\n<p><span><span style=\"font-family: Arial\"><span style=\"font-size: 10pt;color: #000000\"><strong><\/strong><\/span><\/span><\/span><\/p>\n<p><span><span style=\"font-family: Arial\"><span style=\"font-size: 10pt;color: #000000\"><strong>Summary<\/strong>: Learn how to use Windows PowerShell and the Active Directory cmdlets to update user objects in Active Directory.<\/span><\/span><\/span><\/p>\n<p class=\"CodeBlock\" style=\"margin: 4pt 0in 7pt;line-height: 10pt;list-style-type: disc\"><span><span style=\"font-family: 'Lucida Sans Typewriter'\"><span style=\"font-size: 10pt;color: #000000\">&nbsp;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 8pt;line-height: 13.25pt;list-style-type: disc\"><span><span style=\"font-family: Arial;color: #000000\"><span style=\"font-size: 10pt\"><img decoding=\"async\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\" \/>Hey, Scripting Guy! Watching you write a custom function to search Active Directory is about as much fun as watching paint dry. One reason we upgraded to Windows Server 2008 R2 was to gain access to the <\/span><\/span><span style=\"font-size: 10pt\"><a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/ee617195.aspx\"><span style=\"font-family: Arial;color: #0000ff\"><span style=\"text-decoration: underline\">Active Directory cmdlets<\/span><\/span><\/a><\/span><span style=\"font-family: Arial\"><span style=\"font-size: 10pt;color: #000000\">. I am not really good at using them, but I think I should be able to use them to find users that are missing a value for a particular attribute, and then supply a default value for it. Is this possible?<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 8pt;line-height: 13.25pt;list-style-type: disc\"><span><span style=\"font-family: Arial\"><span style=\"font-size: 10pt;color: #000000\">&#8212; MW<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 8pt;line-height: 13.25pt;list-style-type: disc\"><span><span style=\"font-family: Arial\"><span style=\"font-size: 10pt;color: #000000\">&nbsp;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 8pt;line-height: 13.25pt;list-style-type: disc\"><span><span style=\"font-family: Arial;color: #000000\"><span style=\"font-size: 10pt\"><img decoding=\"async\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\" \/> Hello MW, <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 8pt;line-height: 13.25pt;list-style-type: disc\"><span><span style=\"font-family: Arial;color: #000000\"><span style=\"font-size: 10pt\">Microsoft Scripting Guy Ed Wilson here. Watching paint dry could be fun if I had a bag of <\/span><\/span><span style=\"font-size: 10pt\"><a href=\"http:\/\/bit.ly\/bIjgLT\"><span style=\"font-family: Arial;color: #0000ff\"><span style=\"text-decoration: underline\">ANZAC biscuits<\/span><\/span><\/a><span style=\"font-family: Arial;color: #000000\"> and a pot of <\/span><a href=\"http:\/\/en.wikipedia.org\/wiki\/Darjeeling_tea\"><span style=\"font-family: Arial;color: #0000ff\"><span style=\"text-decoration: underline\">Darjeeling tea<\/span><\/span><\/a><span style=\"font-family: Arial;color: #000000\">. I would also want my <\/span><a href=\"http:\/\/zune.net\/en-us\/products\/zunehd\/default.htm\"><span style=\"font-family: Arial;color: #0000ff\"><span style=\"text-decoration: underline\">Zune HD<\/span><\/span><\/a><\/span><span style=\"font-family: Arial\"><span style=\"font-size: 10pt;color: #000000\"> so that I could play some nice jazz. If I had a nice recliner chair, I could get into some paint-drying time. Still, I do not think it would be as much fun as writing Windows PowerShell scripts. The complete SetADPropertyADCmdlets.ps1 script is shown here. <\/span><\/span><\/span><\/p>\n<blockquote>\n<p class=\"CodeBlockScreenedHead\" style=\"background: none transparent scroll repeat 0% 0%;margin: 15pt 12pt 0pt 0in;line-height: 11pt;list-style-type: disc\"><span style=\"font-family: Arial\"><span style=\"font-size: 10pt;color: #000000\"><strong>SetADPropertyADCmdlets.ps1<\/strong><\/span><\/span><\/p>\n<p class=\"CodeBlockScreenedHead\" style=\"background: none transparent scroll repeat 0% 0%;margin: 15pt 12pt 0pt 0in;line-height: 11pt;list-style-type: disc\"><span style=\"color: #000000\">Import-Module<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">ActiveDirectory<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp;<\/span><span style=\"color: #2b91af\">$users<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$i<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$null<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp;<\/span><span style=\"color: #2b91af\">$users<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Get-ADUser<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-SearchBase<\/span><span style=\"color: #808080\"> &#8220;ou=testou,dc=nwtraders,dc=com&#8221; <\/span><span style=\"color: #000000\">-filter<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">*<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">`<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp; <\/span><span style=\"color: #000000\">-property<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">description<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp;<\/span><span style=\"color: #0000ff\">ForEach<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$user<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">in<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$users<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp; <\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp;&nbsp; <\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">([string]::isNullOrEmpty(<\/span><span style=\"color: #2b91af\">$user<\/span><span style=\"color: #000000\">.description))<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;modifying $($user.name)&#8221;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">Set-ADUser<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Identity<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$user<\/span><span style=\"color: #000000\">.distinguishedName<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Description<\/span><span style=\"color: #808080\"> &#8220;added via script&#8221;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #2b91af\">$i++<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">&nbsp; <br \/>&nbsp;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">&nbsp; <br \/> &#8220;modified $i users&#8221;<\/span> <\/p>\n<\/blockquote>\n<p class=\"CodeBlockScreenedHead\" style=\"background: none transparent scroll repeat 0% 0%;margin: 15pt 12pt 0pt 0in;line-height: 11pt;list-style-type: disc\"><span><span style=\"font-family: Arial\"><span style=\"font-size: 10pt;color: #000000\">Before we dive into the script, l like to take a look at my target. I seldom write a script that works with Active Directory without having ADSI Edit and Active Directory Users and Computers open. In fact, I have a custom MMC that contains both of those snap-ins as well as several other tools. The contents of the <strong>testou<\/strong> in the Nwtraders.com domain is shown in the following image.<\/span><\/span><\/span><\/p>\n<p class=\"CodeBlockScreenedHead\" style=\"background: none transparent scroll repeat 0% 0%;margin: 15pt 12pt 0pt 0in;line-height: 11pt;list-style-type: disc\"><span><span style=\"font-family: Arial;color: #000000;font-size: x-small\"><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 8pt;line-height: 13.25pt;list-style-type: disc\"><span><\/span><span><span style=\"font-family: Arial;color: #000000;font-size: x-small\"><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2185.HSG-10-14-10-01_08769286.jpg\"><img decoding=\"async\" title=\"Image of contents of testou in Nwtraders.com domain\" style=\"border-right: 0px;padding-right: 0px;border-top: 0px;padding-left: 0px;border-left: 0px;padding-top: 0px;border-bottom: 0px\" height=\"379\" alt=\"Image of contents of testou in Nwtraders.com domain\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2117.HSG-10-14-10-01_thumb_7B300972.jpg\" width=\"604\" border=\"0\" \/><\/a><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 8pt;line-height: 13.25pt;list-style-type: disc\"><span><span style=\"font-family: Arial\"><span style=\"font-size: 10pt;color: #000000\">As you can see in the previous image, the <strong>testou<\/strong> organizational unit contains both users and computers. In addition, one of the user objects contains a value for the <strong>description<\/strong> property; the other objects do not have a value for the <strong>description<\/strong> property. I only wish to add a <strong>description<\/strong> property value for the users that do not currently have a description; I do not wish to overwrite any existing values. In addition, the description I am going to add is not appropriate for computer objects. Sounds complicated, but it is a very common scenario. The script will need the ability to perform the following actions.<\/span><\/span><\/span><\/p>\n<p class=\"BullList\" style=\"margin: 0in 0in 8pt 0.25in;text-indent: -0.25in;line-height: 13.25pt;list-style-type: disc\"><span style=\"color: #000000\"><span style=\"font-family:\"><span><span style=\"font-family: Symbol\"><span style=\"font-size: 10pt\">&middot;<\/span><\/span><span style=\"line-height: normal;font-family:\"><span style=\"font-family: Arial\"><span style=\"font-size: 7pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><\/span><\/span><span><span style=\"font-family: Arial\"><span style=\"font-size: 10pt\">Search a specific organizational unit for user objects.<\/span><\/span><\/span><\/span><\/p>\n<p class=\"BullList\" style=\"margin: 0in 0in 8pt 0.25in;text-indent: -0.25in;line-height: 13.25pt;list-style-type: disc\"><span style=\"color: #000000\"><span style=\"font-family:\"><span><span style=\"font-family: Symbol\"><span style=\"font-size: 10pt\">&middot;<\/span><\/span><span style=\"line-height: normal;font-family:\"><span style=\"font-family: Arial\"><span style=\"font-size: 7pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><\/span><\/span><span><span style=\"font-family: Arial\"><span style=\"font-size: 10pt\">Find user objects that are missing a value for a specific attribute.<\/span><\/span><\/span><\/span><\/p>\n<p class=\"BullList\" style=\"margin: 0in 0in 8pt 0.25in;text-indent: -0.25in;line-height: 13.25pt;list-style-type: disc\"><span style=\"color: #000000\"><span style=\"font-family:\"><span><span style=\"font-family: Symbol\"><span style=\"font-size: 10pt\">&middot;<\/span><\/span><span style=\"line-height: normal;font-family:\"><span style=\"font-family: Arial\"><span style=\"font-size: 7pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><\/span><\/span><span><span style=\"font-family: Arial\"><span style=\"font-size: 10pt\">Write a default value for user objects that are missing a value for the specific attribute.<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 8pt;line-height: 13.25pt;list-style-type: disc\"><span><span style=\"font-family: Arial\"><span style=\"font-size: 10pt;color: #000000\">The first thing to do when using the Microsoft Active Directory cmdlets is to use the <strong>Import-Module<\/strong> cmdlet to import the <strong>ActiveDirectory<\/strong> module. <\/span><\/span><\/span><\/p>\n<p class=\"Readeraidonly\" style=\"margin: 15pt 12pt 0.25in 0in;line-height: 11pt;list-style-type: disc\"><span><span style=\"font-family: Arial;color: #000000\"><span style=\"font-size: 10pt\">For information about how to obtain and use the Microsoft Active Directory cmdlets, see <\/span><\/span><span style=\"font-size: 10pt\"><a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2010\/01\/25\/hey-scripting-guy-january-25-2010.aspx\"><span style=\"font-family: Arial;color: #0000ff\"><span style=\"text-decoration: underline\">What&rsquo;s up with Active Directory Domain Services Cmdlets?<\/span><\/span><\/a><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 8pt;line-height: 13.25pt;list-style-type: disc\"><span><span style=\"font-family: Arial\"><span style=\"font-size: 10pt;color: #000000\">After the <strong>ActiveDirectory<\/strong> module has been imported, I set the <strong>$users<\/strong> and the <strong>$i<\/strong> variables to <strong>$null<\/strong>. This portion of the SetADPropertyADCmdlets.ps1 script is shown here:<\/span><\/span><\/span><\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #000000\">Import-Module<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">ActiveDirectory<\/span><span style=\"color: #808080\">       <\/p>\n<p><\/span><span style=\"color: #2b91af\">$users<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$i<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$null<\/span><span style=\"color: #808080\"><\/span><\/div>\n<\/blockquote>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 8pt;line-height: 13.25pt;list-style-type: disc\"><span><span style=\"font-family: Arial\"><span style=\"font-size: 10pt;color: #000000\">I now use the <strong>Get-ADUser<\/strong> cmdlet to retrieve users from the <strong>testou<\/strong> in my nwtraders.com domain. The <strong>filter<\/strong> property is required, so I give it the wildcard character <strong>*<\/strong> to tell it I want everything returned. In addition, I specify that I want the <strong>description<\/strong> property returned in the search results. For performance reasons, the <strong>Get-ADUser<\/strong> cmdlet returns only a subset of the available properties from Active Directory Domain Services (AD DS). The search results are stored in the <strong>$users<\/strong> variable. The command is a little long, so I use line continuation backtick character (<strong>`<\/strong>) to move the <strong>&ndash;property<\/strong> description portion of the command to the second line. This is a requirement for publishing the script to the blog. In my original script, the command fit nicely on a single line; it is therefore a single logical line command. The command is shown here:<\/span><\/span><\/span><\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #2b91af\">$users<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">Get-ADUser<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-SearchBase<\/span><span style=\"color: #808080\"> &#8220;ou=testou,dc=nwtraders,dc=com&#8221; <\/span><span style=\"color: #000000\">-filter<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">*<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">`<\/span><span style=\"color: #808080\">       <\/p>\n<p>&nbsp;&nbsp; <\/span><span style=\"color: #000000\">-property<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">description<\/span><span style=\"color: #808080\"><\/span><\/div>\n<\/blockquote>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 8pt;line-height: 13.25pt;list-style-type: disc\"><span><span style=\"font-family: Arial;color: #000000\"><span style=\"font-size: 10pt\">A collection is returned via the <strong>Get-ADUser<\/strong> cmdlet. Therefore, I use the <strong>ForEach<\/strong> statement to walk through the collection. Unfortunately, I cannot <\/span><\/span><span style=\"font-size: 10pt\"><a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/topics\/winpsh\/manual\/pipe.mspx\"><span style=\"font-family: Arial;color: #0000ff\"><span style=\"text-decoration: underline\">pipe<\/span><\/span><\/a><\/span><span style=\"font-family: Arial\"><span style=\"font-size: 10pt;color: #000000\"> the results of the <strong>Get-ADUser<\/strong> cmdlet directly to <strong>Set-ADUser<\/strong>. When inside the collection, I use the static <strong>isNullOrEmpty<\/strong> method from the <strong>system.string<\/strong> .NET Framework class. I have it check the <strong>description<\/strong> property on the <strong>user<\/strong> object. If the property is empty or null, I then display a string that states I am modifying the <strong>user<\/strong> object. This portion of the script is shown here:<\/span><\/span><\/span><\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #0000ff\">ForEach<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #2b91af\">$user<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">in<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$users<\/span><span style=\"color: #000000\">)<\/span><span style=\"color: #808080\">       <\/p>\n<p>&nbsp; <\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">       <\/p>\n<p>&nbsp;&nbsp; <\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">([string]::isNullOrEmpty(<\/span><span style=\"color: #2b91af\">$user<\/span><span style=\"color: #000000\">.description))<\/span><span style=\"color: #808080\">&nbsp; <\/p>\n<p>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">{<\/span><span style=\"color: #808080\">&nbsp; <\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;modifying $($user.name)&#8221;<\/span><span style=\"color: #808080\"><\/span><\/div>\n<\/blockquote>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 8pt;line-height: 13.25pt;list-style-type: disc\"><span><span style=\"font-family: Arial\"><span style=\"font-size: 10pt;color: #000000\">To modify the user object, use the <strong>Set-ADUser<\/strong> cmdlet. The <strong>identity<\/strong> parameter is used to specify which b object to modify; this parameter will accept a distinguished name, the object GUID, the security identifier (SID), the SAM account name, or the name of the object. Here, I chose the <strong>distinguishedname<\/strong> property from the <strong>user<\/strong> object. The <strong>description<\/strong> parameter holds the value to add to the <strong>description<\/strong> attribute on the object. This command is shown here:<\/span><\/span><\/span><\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #000000\">Set-ADUser<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Identity<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #2b91af\">$user<\/span><span style=\"color: #000000\">.distinguishedName<\/span><span style=\"color: #808080\">&nbsp;<\/span><span style=\"color: #000000\">-Description<\/span><span style=\"color: #808080\"> &#8220;added via script&#8221;<\/span> <\/div>\n<\/blockquote>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 8pt;line-height: 13.25pt;list-style-type: disc\"><span><span style=\"font-family: Arial\"><span style=\"font-size: 10pt;color: #000000\">The last two things to do are to increment the <strong>$i<\/strong> counter variable and display a summary string. This portion of the script is shown here:<\/span><\/span><\/span><\/p>\n<blockquote>\n<div class=\"code\"><span style=\"color: #2b91af\">$i++<\/span><span style=\"color: #808080\">       <\/p>\n<p>&nbsp;&nbsp;&nbsp; <\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">       <\/p>\n<p>&nbsp;<\/span><span style=\"color: #000000\">}<\/span><span style=\"color: #808080\">       <\/p>\n<p> &#8220;modified $i users&#8221;        <br \/><\/span><\/div>\n<\/blockquote>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 8pt;line-height: 13.25pt;list-style-type: disc\"><span><span style=\"font-family: Arial\"><span style=\"font-size: 10pt;color: #000000\"><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 8pt;line-height: 13.25pt;list-style-type: disc\"><span><span style=\"font-family: Arial\"><span style=\"font-size: 10pt;color: #000000\">When the script runs in the Windows PowerShell ISE, the output appears that is shown in the following image.<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 8pt;line-height: 13.25pt;list-style-type: disc\"><span><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3678.HSG-10-14-10-02_24C3D4A6.jpg\"><img decoding=\"async\" title=\"Image of output that appears in Windows PowerShell ISE\" style=\"border-right: 0px;padding-right: 0px;border-top: 0px;padding-left: 0px;border-left: 0px;padding-top: 0px;border-bottom: 0px\" height=\"436\" alt=\"Image of output that appears in Windows PowerShell ISE\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8054.HSG-10-14-10-02_thumb_11367505.jpg\" width=\"604\" border=\"0\" \/><\/a><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 8pt;line-height: 13.25pt;list-style-type: disc\"><span><\/span><span><span style=\"font-family: Arial\"><span style=\"font-size: 10pt;color: #000000\">Active Directory Users and Computers is used to verify that the changes were completed. Keep in mind that you might need to hit refresh (F5) a few times before the changes appear. In addition, depending on your network topology, it might actually take a minute or two. On my system, the changes shown in the following image took a few seconds of pressing refresh before they appeared.<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 8pt;line-height: 13.25pt;list-style-type: disc\"><span><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7888.HSG-10-14-10-03_28EDAC6B.jpg\"><img decoding=\"async\" title=\"Image of changes that appear after refreshing\" style=\"border-right: 0px;padding-right: 0px;border-top: 0px;padding-left: 0px;border-left: 0px;padding-top: 0px;border-bottom: 0px\" height=\"379\" alt=\"Image of changes that appear after refreshing\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5340.HSG-10-14-10-03_thumb_6E923689.jpg\" width=\"604\" border=\"0\" \/><\/a><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 8pt;line-height: 13.25pt;list-style-type: disc\"><span><span style=\"font-family: Arial\"><span style=\"color: #000000\"><span style=\"font-size: 10pt\">MW, that is all there is to using the Microsoft Active Directory cmdlets to find objects with missing values and then assign default values to those objects. Active Directory Week draws to an end. Join us tomorrow when we will have a guest blogger talk about the Windows PowerShell Scripting Community. You should not miss this excellent article. <\/span><span><span style=\"font-size: 10pt\">&nbsp;<\/span><\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 8pt;line-height: 13.25pt;list-style-type: disc\"><span><span style=\"font-family: Arial;color: #000000\"><span style=\"font-size: 10pt\">We invite you to follow us on <\/span><\/span><span style=\"font-size: 10pt\"><a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\"><span style=\"font-family: Arial;color: #0000ff\"><span style=\"text-decoration: underline\">Twitter<\/span><\/span><\/a><span style=\"font-family: Arial;color: #000000\"> and <\/span><a href=\"http:\/\/bit.ly\/scriptingguysfacebook\"><span style=\"font-family: Arial;color: #0000ff\"><span style=\"text-decoration: underline\">Facebook<\/span><\/span><\/a><span style=\"font-family: Arial;color: #000000\">. If you have any questions, send email to us at <\/span><a href=\"mailto:scripter@microsoft.com\" target=\"_blank\"><span style=\"font-family: Arial;color: #0000ff\"><span style=\"text-decoration: underline\">scripter@microsoft.com<\/span><\/span><\/a><span style=\"font-family: Arial;color: #000000\">, or post them on the <\/span><a href=\"http:\/\/social.technet.microsoft.com\/Forums\/en\/ITCG\/threads\/\"><span style=\"font-family: Arial;color: #0000ff\"><span style=\"text-decoration: underline\">Official Scripting Guys Forum<\/span><\/span><\/a><\/span><span style=\"font-family: Arial\"><span style=\"font-size: 10pt;color: #000000\">. See you tomorrow. Until then, peace.<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin: 0in 0in 8pt;line-height: 13.25pt;list-style-type: disc\"><span style=\"font-family:\"><span style=\"font-family: 'Segoe UI'\"><span style=\"font-size: 10pt;color: #000000\">&nbsp;<\/span><\/span><\/span><\/p>\n<p style=\"margin: 0in 0in 8pt;line-height: 13.25pt;list-style-type: disc\"><strong><span style=\"font-family:\"><span style=\"font-family: 'Segoe UI'\"><span style=\"font-size: 10pt;color: #000000\">Ed Wilson and Craig Liebendorfer, Scripting Guys<\/span><\/span><\/span><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn how to use Windows PowerShell and the Active Directory cmdlets to update user objects in Active Directory. &nbsp; Hey, Scripting Guy! Watching you write a custom function to search Active Directory is about as much fun as watching paint dry. One reason we upgraded to Windows Server 2008 R2 was to gain access [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[7,3,8,20,45],"class_list":["post-16821","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-scripting-guy","tag-searching-active-directory","tag-user-accounts","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Learn how to use Windows PowerShell and the Active Directory cmdlets to update user objects in Active Directory. &nbsp; Hey, Scripting Guy! Watching you write a custom function to search Active Directory is about as much fun as watching paint dry. One reason we upgraded to Windows Server 2008 R2 was to gain access [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/16821","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\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=16821"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/16821\/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=16821"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=16821"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=16821"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}