{"id":2400,"date":"2013-12-17T00:01:00","date_gmt":"2013-12-17T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/12\/17\/use-powershell-to-work-with-rodc-accounts\/"},"modified":"2013-12-17T00:01:00","modified_gmt":"2013-12-17T00:01:00","slug":"use-powershell-to-work-with-rodc-accounts","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-work-with-rodc-accounts\/","title":{"rendered":"Use PowerShell to Work with RODC Accounts"},"content":{"rendered":"<p><strong>Summary<\/strong>: Microsoft premier field engineer,&nbsp;Ian Farr, talks about using Windows PowerShell to work with RODC accounts.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. Today I would like to introduce a new guest blogger, Ian Farr. Ian tells us about himself:<\/p>\n<p style=\"padding-left: 30px\">I started out writing UNIX shell scripts to automate simple tasks. Then as a Windows IT pro, I discovered VBScript, and it ignited a passion for automation. Over the years, I&#8217;ve used batch files, KiXtart, JScript, HTAs, Perl, JavaScript, and Python. I love solving problems with scripts, and I&#8217;ve written code for several large enterprise environments. I now work as a premier field engineer at Microsoft, teaching Windows PowerShell and helping my customers with their own scripts.<\/p>\n<p>Today, I&rsquo;d like to share with you my function <a href=\"http:\/\/gallery.technet.microsoft.com\/scriptcenter\/Get-ADRodcAuthenticatedNotR-daf51490\" target=\"_blank\">Get-ADRodcAuthenticatedNotRevealed.ps1<\/a>.<\/p>\n<p>One of my customers has a large number of <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/cc772234(v=ws.10).aspx\" target=\"_blank\">Read-only domain controllers<\/a> (RODCs). Each one is configured (by using password replication policies) to only store the account credentials of specific low-privileged user and computer accounts. If an &ldquo;allowed&rdquo; account authenticates against its designated RODC, its credentials are cached on that RODC. The account is then added to the &ldquo;revealed&rdquo; list. If the RODC loses connectivity to the central site, it can still authenticate accounts in its revealed list.<\/p>\n<p>Of course, an RODC can authenticate accounts that are not in an applicable password replication policy. To do this, it must communicate with a Read-Write domain controller. All accounts that an RODC has authenticated, including those in the revealed list, can be found in the appropriately named authenticated list. By now, you&rsquo;re probably thinking, &ldquo;What does all of have to do with Windows PowerShell and scripting?&rdquo;<\/p>\n<p>Hang on&hellip;I&rsquo;m almost there.<\/p>\n<p>RODCs are most suited to branch office locations, so it&rsquo;s reasonable to assume that each RODC has authenticated accounts from applicable allowed password replication policies. It&rsquo;s also reasonable to assume that user and computer accounts that are not defined in a password replication policy may have been authenticated&mdash;for example, perhaps a roaming user has visited and plugged in their laptop to the LAN.<\/p>\n<p>You may also see authenticated accounts that are part of a &ldquo;denied&rdquo; password replication policy. Built-in privileged groups and accounts, by default, do not have their credentials stored on an RODC.<\/p>\n<p>Now to analyse specific RODC usage. How do you determine which accounts are stored in the &ldquo;authenticated&rdquo; list, but don&rsquo;t appear in the &ldquo;revealed&rdquo; list?<\/p>\n<p>At last&hellip;some Windows PowerShell!<\/p>\n<p>I&rsquo;ve published the <a href=\"http:\/\/gallery.technet.microsoft.com\/scriptcenter\/Get-ADRodcAuthenticatedNotR-daf51490\" target=\"_blank\">Get-ADRodcAuthenticatedNotRevealed<\/a> function on the TechNet Script Center Repository. It will return account objects that are authenticated but not revealed.<\/p>\n<p>You could add the script to <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/ee692764.aspx#EDAA\" target=\"_blank\">$profile<\/a>, so it is loaded to the PSDrive function (see&nbsp;<a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/09\/07\/use-powershell-to-work-easily-with-drives-and-paths.aspx\" target=\"_blank\">Use PowerShell to Work Easily with Dives and Paths<\/a>) when Windows PowerShell opens. Or you can access it as needed by <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/ee176949.aspx#ECAA\" target=\"_blank\">dot sourcing<\/a> the script file:<\/p>\n<p style=\"padding-left: 30px\">. .\\Get-ADRodcAuthenticatedNotRevealed.ps1<\/p>\n<p>Here&rsquo;s a suggested way to use the function:<\/p>\n<p style=\"padding-left: 30px\">Get-ADDomainController -Filter {IsReadOnly -eq $True} | Get-ADRodcAuthenticatedNotRevealed&nbsp;<\/p>\n<p>Here, we get all of the RODCs from the domain that the user is currently logged in to and pipe them one-by-one into the function. This line could happily be part of a script that defines or references the function.<\/p>\n<p>We can just as easily pipe a hand-typed list of RODCs:<\/p>\n<p style=\"padding-left: 30px\">&ldquo;NINJARODC01&rdquo;, &ldquo;ninjarodc02&rdquo; | Get-ADRodcAuthenticatedNotRevealed&nbsp;&nbsp;<\/p>\n<p>Or the contents of a text file:<\/p>\n<p style=\"padding-left: 30px\">Get-Content &ndash;Path rodc.txt | Get-ADRodcAuthenticatedNotRevealed&nbsp;<\/p>\n<p>By the way, this is the geeky way to get the contents of that file:<\/p>\n<p style=\"padding-left: 30px\">${c:rodc.txt} | Get-ADRodcAuthenticatedNotRevealed&nbsp;&nbsp;<\/p>\n<p>The <strong>Get-ADRodcAuthenticatedNotRevealed<\/strong> function processes each RODC that is passed down the pipeline with a <strong>Process<\/strong> script block. Script blocks are the building blocks of Windows PowerShell. They are recognized by those interesting curly braces you see everywhere: <strong>{ }<\/strong>.<\/p>\n<p>Next, we compare the output of two cmdlets. The first cmdlet gets all authenticated accounts from the RODC currently in the pipeline:<\/p>\n<p style=\"padding-left: 30px\">$AuthenticatedAccounts = Get-ADDomainControllerPasswordReplicationPolicyUsage -Identity $Rodc -AuthenticatedAccounts<\/p>\n<p>The second gets all the revealed accounts:<\/p>\n<p style=\"padding-left: 30px\">$RevealedAccounts = Get-ADDomainControllerPasswordReplicationPolicyUsage -Identity $Rodc -RevealedAccounts<\/p>\n<p>Here&rsquo;s the comparison:<\/p>\n<p style=\"padding-left: 30px\">Comparison = Compare-Object -ReferenceObject $AuthenticatedAccounts -DifferenceObject $RevealedAccounts<\/p>\n<p>After the comparison is performed, we filter on those accounts that only appear in the reference object by using the side indicator output, <strong>&ldquo;&lt; =&rdquo;<\/strong>, as shown here:<\/p>\n<p style=\"padding-left: 30px\">$Results = $Comparison | Where-Object {$_.SideIndicator -eq &#8220;&lt;=&#8221;}&nbsp;<\/p>\n<p>&nbsp;Here&rsquo;s what the <strong>$Comparison<\/strong> side indicators represent:<\/p>\n<ul>\n<li>&ldquo;&lt;=&rdquo; implies that these accounts <strong>only<\/strong> appear in the AuthenticatedAccounts list<\/li>\n<li>&ldquo;=&gt;&rdquo; implies that the accounts appear <strong>only<\/strong> in the RevealedAccounts list<\/li>\n<li>&ldquo;==&rdquo; implies that the accounts are present in both lists (the <strong>IncludeEqual<\/strong> switch has to be supplied to the <strong>Compare-Object<\/strong> cmdlet)<\/li>\n<\/ul>\n<p><strong>$Results<\/strong> now contains authenticated accounts that have not been revealed. Let&rsquo;s return them to the calling scope:<\/p>\n<p style=\"padding-left: 30px\">$Results.InputObject<\/p>\n<p>We could export the account objects to XML, or as in the following example, to a file:<\/p>\n<p style=\"padding-left: 30px\">$Results.InputObject | Export-CSV -Path &#8220;$($Rodc)_AuthenticatedNotRevealed.csv&#8221; -Force<\/p>\n<p>We&rsquo;ll end up with a .csv file of authenticated but not revealed accounts for each RODC processed. It will look something like this:<\/p>\n<p style=\"padding-left: 30px\">NINJARODC01_AuthenticatedNotRevealed.csv<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7713.hsg-12-17-13-1.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7713.hsg-12-17-13-1.png\" alt=\"Image of command output\" \/><\/a>&nbsp; &nbsp;<\/p>\n<p>Now to write a function to analyse the <strong>Get-ADRodcAuthenticatedNotRevealed<\/strong> output&hellip;<\/p>\n<p>Here is the function: <a href=\"http:\/\/gallery.technet.microsoft.com\/scriptcenter\/Get-ADRodcAuthenticatedNotR-daf51490\" target=\"_blank\">Get-ADRodcAuthenticatedNotRevealed.ps1<\/a>.<\/p>\n<p>~Ian<\/p>\n<p>Thank you, Ian, for sharing your knowledge and time.<\/p>\n<p>I 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=\"mailto: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.<\/p>\n<p><strong>Ed Wilson, Microsoft Scripting Guy<\/strong>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft premier field engineer,&nbsp;Ian Farr, talks about using Windows PowerShell to work with RODC accounts. Microsoft Scripting Guy, Ed Wilson, is here. Today I would like to introduce a new guest blogger, Ian Farr. Ian tells us about himself: I started out writing UNIX shell scripts to automate simple tasks. Then as a Windows [&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,168,56,472,3,45],"class_list":["post-2400","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-domains","tag-guest-blogger","tag-ian-farr","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft premier field engineer,&nbsp;Ian Farr, talks about using Windows PowerShell to work with RODC accounts. Microsoft Scripting Guy, Ed Wilson, is here. Today I would like to introduce a new guest blogger, Ian Farr. Ian tells us about himself: I started out writing UNIX shell scripts to automate simple tasks. Then as a Windows [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2400","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=2400"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2400\/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=2400"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=2400"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=2400"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}