{"id":7817,"date":"2020-10-29T12:03:52","date_gmt":"2020-10-29T16:03:52","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=7817"},"modified":"2020-11-11T11:59:18","modified_gmt":"2020-11-11T16:59:18","slug":"distinguished-parsing-with-powershell-and-regex","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/active-directory\/7817\/distinguished-parsing-with-powershell-and-regex\/","title":{"rendered":"Distinguished Parsing with PowerShell and Regex"},"content":{"rendered":"\n<p>The other day I'm chatting with my friend Gladys Kravitz about Active Directory and she makes an off-hand remark about parsing out organizational unit names from a distinguished name. On one hand, this is a pretty simple task, assuming a proper distinguished name from the Active Directory cmdlets. All you really need to do is split the string.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$ou = \"OU=Foo,OU=Top,DC=Company,DC=pri\"\n$ou.split(\",\")[0]<\/code><\/pre>\n\n\n\n<p>The code is splitting on the comma and selecting the first element in the array.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"823\" height=\"265\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/ou-split.png\" alt=\"\" class=\"wp-image-7818\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/ou-split.png 823w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/ou-split-300x97.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/ou-split-768x247.png 768w\" sizes=\"auto, (max-width: 823px) 100vw, 823px\" \/><\/figure>\n\n\n\n<p>But I thought there's like an alternative. And what if I want just the name of the top level OU, i.e. Foo? So naturally I turned to regular expressions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Don't Be Greedy<\/h2>\n\n\n\n<p>I  began by creating a set of test distinguished name values.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$DN = @(\"OU=Foo,OU=Top,DC=Company,DC=pri\",\n    \"OU=Foo123,OU=FooBar,DC=Company,DC=pri\",\n    \"ou=Foo,ou=Top,dc=Company,dc=pri\",\n    \"OU=Gladys Kravitz Monitors,OU=Top,DC=Company,DC=pri\",\n    \"OU=A723-Test,OU=Top,OU=Middle,DC=Company,DC=pri\",\n    \"OU=JEA_Operators,DC=Company,DC=Pri\",\n    \"CN=Users,DC=Company,DC=pri\",\n    \"CN=ArtD,OU=IT,DC=Company,DC=Pri\",\n    \"cn=johnd,ou=sales,dc=company,dc=pri\",\n    \"CN=SamS,OU=This,OU=That,DC=Company,DC=Pri\",\n    \"OU=Domain Controllers,DC=Company,DC=Pri\")<\/code><\/pre>\n\n\n\n<p>If you look closely, you'll see I am using a variety of forms since I may not always be able to guarantee what the data will look like. I'm also starting this exercise from the perspective of getting the top OU name from an OU distinguished name. I have included test values that I know should fail. <em>When developing with a regex pattern it is important to test with data you know should fail. <\/em><\/p>\n\n\n\n<p>With this data I started with this regular expression pattern:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">[regex]$rx = \"^(ou|OU)=.*(?=,)\"<\/code><\/pre>\n\n\n\n<p>The pattern says, \"Anchor at the start of line line (^) and look for the string \"ou\" or (|) \"OU\" followed by =. Then any characters (.*) where if you look ahead you see a comma (?=,).\" Let's try with the first element in the array.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"722\" height=\"405\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/greed.png\" alt=\"\" class=\"wp-image-7819\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/greed.png 722w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/greed-300x168.png 300w\" sizes=\"auto, (max-width: 722px) 100vw, 722px\" \/><\/figure>\n\n\n\n<p>This mostly worked. The problem is that the pattern matched on every possible string. In other words, the regular expression pattern was greedy. Most of the time this isn't a problem. But, here I want the regex pattern to stop after the first OU match.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">[regex]$rx = \"^(ou|OU)=.*?(?=,)\"<\/code><\/pre>\n\n\n\n<p>The main difference is the \"?\" inserted after .\"*\". This makes the pattern stop after the first match. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"751\" height=\"489\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/non-greedy.png\" alt=\"\" class=\"wp-image-7821\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/non-greedy.png 751w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/non-greedy-300x195.png 300w\" sizes=\"auto, (max-width: 751px) 100vw, 751px\" \/><\/figure>\n\n\n\n<p>Now I can process array of names.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"329\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-names-1-1024x329.png\" alt=\"\" class=\"wp-image-7822\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-names-1-1024x329.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-names-1-300x96.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-names-1-768x247.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-names-1-850x273.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-names-1.png 1425w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Not as clean as I'd like since I'm getting blanks for the strings that don't match. This might be better.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"233\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-names-2-1024x233.png\" alt=\"\" class=\"wp-image-7823\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-names-2-1024x233.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-names-2-300x68.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-names-2-768x175.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-names-2-850x193.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-names-2.png 1487w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Now I'm only getting the value if there is a match. But I want to take this even further.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Named Captures<\/h2>\n\n\n\n<p>I've decided I want get the name of the first OU, such as Foo and Foo123. To do this I'll use a named capture. Here's my revised regex pattern.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">[regex]$rx = \"^(ou|OU)=(?&lt;OUName>.*?(?=,))\"<\/code><\/pre>\n\n\n\n<p>The main difference is that I am now defining a name, OUName, for anything that matches in the last part of the pattern which is wrapped in parentheses. Adding \"?&lt;OUName>\" in front of the non-greedy pattern, defines the name. Matching now includes a new group.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"859\" height=\"968\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/named-cap.png\" alt=\"\" class=\"wp-image-7824\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/named-cap.png 859w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/named-cap-266x300.png 266w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/named-cap-768x865.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/named-cap-300x338.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/named-cap-850x958.png 850w\" sizes=\"auto, (max-width: 859px) 100vw, 859px\" \/><\/figure>\n\n\n\n<p>Here's a scripting trick to get just named capture.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"744\" height=\"375\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/named-cap2.png\" alt=\"\" class=\"wp-image-7825\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/named-cap2.png 744w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/named-cap2-300x151.png 300w\" sizes=\"auto, (max-width: 744px) 100vw, 744px\" \/><\/figure>\n\n\n\n<p>Which means I can process my array:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$dn | Where-Object { $rx.IsMatch($_) } | ForEach-Object { $rx.Match($_).groups[\"OUName\"].Value }<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"206\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/named-cap3-1024x206.png\" alt=\"\" class=\"wp-image-7826\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/named-cap3-1024x206.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/named-cap3-300x60.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/named-cap3-768x155.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/named-cap3-1536x309.png 1536w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/named-cap3-850x171.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/named-cap3.png 1694w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>My next step would normally be to build a function based on this code.  But I'm not finished.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Get Top OU Name<\/h2>\n\n\n\n<p>What about distinguished names for users and groups? I want to be able to parse out the name of the top level organizational unit. I'll test with this.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$art = \"CN=ArtD,OU=IT,DC=Company,DC=Pri\"<\/code><\/pre>\n\n\n\n<p>The tricky part is that the string might start with CN or OU. Here's yet another version of my regex pattern.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">[regex]$rx = \"^(((CN=.*?))?)(ou|OU)=(?&lt;OUName>.*?(?=,))\"<\/code><\/pre>\n\n\n\n<p>With this pattern I'm looking for something that might start with <br>\"CN=something\" at the beginning.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">^(((CN=.*?))?)<\/code><\/pre>\n\n\n\n<p>The  pattern is using a non-greedy match. The overall pattern is <em>optional<\/em>. That is, it might exist. The format if \"( &lt;your-pattern>?)\". Let's see if it works.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"692\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/top-ou-test-1024x692.png\" alt=\"\" class=\"wp-image-7827\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/top-ou-test-1024x692.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/top-ou-test-300x203.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/top-ou-test-768x519.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/top-ou-test-850x574.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/top-ou-test.png 1107w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Looks good. Although if the string started with \"cn\", it will fail.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"367\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/case-fail-1024x367.png\" alt=\"\" class=\"wp-image-7828\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/case-fail-1024x367.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/case-fail-300x107.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/case-fail-768x275.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/case-fail-850x305.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/case-fail.png 1295w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>This is one potential pitfall when working with regular expressions in PowerShell and why I added a variety of casings in my $DN test data set. A better way to avoid case issues is to define the regex object like this.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$rx = [System.Text.RegularExpressions.Regex]::new(\"^(((CN=.*?))?)OU=(?&lt;OUName>.*?(?=,))\",\"IgnoreCase\")<\/code><\/pre>\n\n\n\n<p>Now it won't matter if the string uses OU, ou or oU. They will all match.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"947\" height=\"616\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/ignore-case.png\" alt=\"\" class=\"wp-image-7829\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/ignore-case.png 947w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/ignore-case-300x195.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/ignore-case-768x500.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/ignore-case-850x553.png 850w\" sizes=\"auto, (max-width: 947px) 100vw, 947px\" \/><\/figure>\n\n\n\n<p>And using my test data now processes the user and group names.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"281\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-topou-1024x281.png\" alt=\"\" class=\"wp-image-7830\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-topou-1024x281.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-topou-300x82.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-topou-768x211.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-topou-1536x422.png 1536w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-topou-850x233.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-topou.png 1722w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Excellent. I'll build a function based on this code that will process a distinguished name and provide the name of the first or top organizational unit name.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Function Get-TopOUName {\n    [cmdletbinding()]\n    Param(\n        [Parameter(Position = 0, Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]\n        [alias(\"dn\")]\n        [string]$DistinguishedName\n    )\n\n    Begin {\n        Write-Verbose \"[$((Get-Date).TimeofDay) BEGIN  ] Starting $($myinvocation.mycommand)\"\n        #ignore case\n        $rx = [System.Text.RegularExpressions.Regex]::new(\"^(((CN=.*?))?)OU=(?&lt;OUName>.*?(?=,))\",\"IgnoreCase\")\n    } #begin\n\n    Process {\n        Write-Verbose \"[$((Get-Date).TimeofDay) PROCESS] Processing $DistinguishedName\"\n        If ($rx.IsMatch($DistinguishedName) ) {\n            $rx.Match($DistinguishedName).groups[\"OUName\"].Value\n        }\n    } #process\n\n    End {\n        Write-Verbose \"[$((Get-Date).TimeofDay) END    ] Ending $($myinvocation.mycommand)\"\n    } #end\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"559\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-topouname-1-1024x559.png\" alt=\"\" class=\"wp-image-7831\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-topouname-1-1024x559.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-topouname-1-300x164.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-topouname-1-768x419.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-topouname-1-1536x838.png 1536w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-topouname-1-850x464.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-topouname-1.png 1653w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>If you look closely, you'll see that CN=Users,DC=Company,DC=pri didn't produce a result which means my pattern is working. Let's test this with Active Directory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Get-ADUser -filter * | Select-Object Name,SamAccountName,\n@{Name=\"OU\";Expression={Get-TopOUName $_.distinguishedname}},distinguishedname<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"547\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-aduser-ou-1024x547.png\" alt=\"\" class=\"wp-image-7832\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-aduser-ou-1024x547.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-aduser-ou-300x160.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-aduser-ou-768x410.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-aduser-ou-850x454.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-aduser-ou.png 1462w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Those first few accounts aren't in an OU so the result is as expected. But now I have a tool I can use.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"457\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-aduser-ou-count-1024x457.png\" alt=\"\" class=\"wp-image-7833\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-aduser-ou-count-1024x457.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-aduser-ou-count-300x134.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-aduser-ou-count-768x343.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-aduser-ou-count-850x380.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/get-aduser-ou-count.png 1384w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Learn More<\/h2>\n\n\n\n<p>You may not have a practical need for my patterns or codes to work with Active Directory. But I hope you'll learn from how I approached the problem and illustrated a few regular expression concepts. If you want to know more about regular expressions, I have an entire <a href=\"https:\/\/pluralsight.pxf.io\/r6vNG\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Pluralsight course<\/a> on the subject.<\/p>\n\n\n\n<p>If simple string splitting works, by all means take the easy route. But sometimes you might needs something a bit more sophisticated and I think you'll find regular expressions to be an elegant solution.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The other day I&#8217;m chatting with my friend Gladys Kravitz about Active Directory and she makes an off-hand remark about parsing out organizational unit names from a distinguished name. On one hand, this is a pretty simple task, assuming a proper distinguished name from the Active Directory cmdlets. All you really need to do is&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"New on the blog: Distinguished Parsing with #PowerShell and Regex","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[7,4,8],"tags":[534,502,540],"class_list":["post-7817","post","type-post","status-publish","format-standard","hentry","category-active-directory","category-powershell","category-scripting","tag-powershell","tag-regular-expression","tag-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Distinguished Parsing with PowerShell and Regex &#8226; The Lonely Administrator<\/title>\n<meta name=\"description\" content=\"I&#039;m parsing distinguished name strings with PowerShell and regex, but you can use the same techniques for your own scripting work.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jdhitsolutions.com\/blog\/active-directory\/7817\/distinguished-parsing-with-powershell-and-regex\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Distinguished Parsing with PowerShell and Regex &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"I&#039;m parsing distinguished name strings with PowerShell and regex, but you can use the same techniques for your own scripting work.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/active-directory\/7817\/distinguished-parsing-with-powershell-and-regex\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2020-10-29T16:03:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-11-11T16:59:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/ou-split.png\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/active-directory\\\/7817\\\/distinguished-parsing-with-powershell-and-regex\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/active-directory\\\/7817\\\/distinguished-parsing-with-powershell-and-regex\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Distinguished Parsing with PowerShell and Regex\",\"datePublished\":\"2020-10-29T16:03:52+00:00\",\"dateModified\":\"2020-11-11T16:59:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/active-directory\\\/7817\\\/distinguished-parsing-with-powershell-and-regex\\\/\"},\"wordCount\":839,\"commentCount\":5,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/active-directory\\\/7817\\\/distinguished-parsing-with-powershell-and-regex\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/ou-split.png\",\"keywords\":[\"PowerShell\",\"Regular Expression\",\"Scripting\"],\"articleSection\":[\"Active Directory\",\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/active-directory\\\/7817\\\/distinguished-parsing-with-powershell-and-regex\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/active-directory\\\/7817\\\/distinguished-parsing-with-powershell-and-regex\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/active-directory\\\/7817\\\/distinguished-parsing-with-powershell-and-regex\\\/\",\"name\":\"Distinguished Parsing with PowerShell and Regex &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/active-directory\\\/7817\\\/distinguished-parsing-with-powershell-and-regex\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/active-directory\\\/7817\\\/distinguished-parsing-with-powershell-and-regex\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/ou-split.png\",\"datePublished\":\"2020-10-29T16:03:52+00:00\",\"dateModified\":\"2020-11-11T16:59:18+00:00\",\"description\":\"I'm parsing distinguished name strings with PowerShell and regex, but you can use the same techniques for your own scripting work.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/active-directory\\\/7817\\\/distinguished-parsing-with-powershell-and-regex\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/active-directory\\\/7817\\\/distinguished-parsing-with-powershell-and-regex\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/active-directory\\\/7817\\\/distinguished-parsing-with-powershell-and-regex\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/ou-split.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/ou-split.png\",\"width\":823,\"height\":265},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/active-directory\\\/7817\\\/distinguished-parsing-with-powershell-and-regex\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Active Directory\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/active-directory\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Distinguished Parsing with PowerShell and Regex\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/\",\"name\":\"The Lonely Administrator\",\"description\":\"Practical Advice for the Automating IT Pro\",\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\",\"name\":\"Jeffery Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"caption\":\"Jeffery Hicks\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Distinguished Parsing with PowerShell and Regex &#8226; The Lonely Administrator","description":"I'm parsing distinguished name strings with PowerShell and regex, but you can use the same techniques for your own scripting work.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jdhitsolutions.com\/blog\/active-directory\/7817\/distinguished-parsing-with-powershell-and-regex\/","og_locale":"en_US","og_type":"article","og_title":"Distinguished Parsing with PowerShell and Regex &#8226; The Lonely Administrator","og_description":"I'm parsing distinguished name strings with PowerShell and regex, but you can use the same techniques for your own scripting work.","og_url":"https:\/\/jdhitsolutions.com\/blog\/active-directory\/7817\/distinguished-parsing-with-powershell-and-regex\/","og_site_name":"The Lonely Administrator","article_published_time":"2020-10-29T16:03:52+00:00","article_modified_time":"2020-11-11T16:59:18+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/ou-split.png","type":"","width":"","height":""}],"author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/active-directory\/7817\/distinguished-parsing-with-powershell-and-regex\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/active-directory\/7817\/distinguished-parsing-with-powershell-and-regex\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Distinguished Parsing with PowerShell and Regex","datePublished":"2020-10-29T16:03:52+00:00","dateModified":"2020-11-11T16:59:18+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/active-directory\/7817\/distinguished-parsing-with-powershell-and-regex\/"},"wordCount":839,"commentCount":5,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/active-directory\/7817\/distinguished-parsing-with-powershell-and-regex\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/ou-split.png","keywords":["PowerShell","Regular Expression","Scripting"],"articleSection":["Active Directory","PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/active-directory\/7817\/distinguished-parsing-with-powershell-and-regex\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/active-directory\/7817\/distinguished-parsing-with-powershell-and-regex\/","url":"https:\/\/jdhitsolutions.com\/blog\/active-directory\/7817\/distinguished-parsing-with-powershell-and-regex\/","name":"Distinguished Parsing with PowerShell and Regex &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/active-directory\/7817\/distinguished-parsing-with-powershell-and-regex\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/active-directory\/7817\/distinguished-parsing-with-powershell-and-regex\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/ou-split.png","datePublished":"2020-10-29T16:03:52+00:00","dateModified":"2020-11-11T16:59:18+00:00","description":"I'm parsing distinguished name strings with PowerShell and regex, but you can use the same techniques for your own scripting work.","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/active-directory\/7817\/distinguished-parsing-with-powershell-and-regex\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/active-directory\/7817\/distinguished-parsing-with-powershell-and-regex\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/active-directory\/7817\/distinguished-parsing-with-powershell-and-regex\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/ou-split.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/ou-split.png","width":823,"height":265},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/active-directory\/7817\/distinguished-parsing-with-powershell-and-regex\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Active Directory","item":"https:\/\/jdhitsolutions.com\/blog\/category\/active-directory\/"},{"@type":"ListItem","position":2,"name":"Distinguished Parsing with PowerShell and Regex"}]},{"@type":"WebSite","@id":"https:\/\/jdhitsolutions.com\/blog\/#website","url":"https:\/\/jdhitsolutions.com\/blog\/","name":"The Lonely Administrator","description":"Practical Advice for the Automating IT Pro","publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jdhitsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9","name":"Jeffery Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","caption":"Jeffery Hicks"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":1885,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1885\/updating-multi-valued-active-directory-properties-part-1\/","url_meta":{"origin":7817,"position":0},"title":"Updating Multi-Valued Active Directory Properties Part 1","author":"Jeffery Hicks","date":"December 8, 2011","format":false,"excerpt":"Yesterday on Twitter, I got a tweet from @Docsmooth regarding how to update a multivalued property in Active Directory. There are a number of ways to handle this, especially from PowerShell naturally, so I tweeted one way in a series of tweets. But that's a hard way to learn something,\u2026","rel":"","context":"In &quot;Active Directory&quot;","block_context":{"text":"Active Directory","link":"https:\/\/jdhitsolutions.com\/blog\/category\/active-directory\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":8173,"url":"https:\/\/jdhitsolutions.com\/blog\/active-directory\/8173\/climbing-trees-in-powershell\/","url_meta":{"origin":7817,"position":1},"title":"Climbing Trees in PowerShell","author":"Jeffery Hicks","date":"February 15, 2021","format":false,"excerpt":"I'm continuing with my renewed interest in Active Directory, and how I can take advantage of PowerShell. This is a topic I've been working with since the PowerShell v2 days. I have a lot of old code. Some of which I've decided to dust off and polish up. One topic\u2026","rel":"","context":"In &quot;Active Directory&quot;","block_context":{"text":"Active Directory","link":"https:\/\/jdhitsolutions.com\/blog\/category\/active-directory\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/02\/canonical-ou-sort.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/02\/canonical-ou-sort.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/02\/canonical-ou-sort.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/02\/canonical-ou-sort.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":25,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/25\/techmentor-dsquery-and-dsmod-examples\/","url_meta":{"origin":7817,"position":2},"title":"Techmentor: DSQuery and DSMod examples","author":"Jeffery Hicks","date":"March 21, 2006","format":false,"excerpt":"During the command line scripting session, I demonstrated how to use the directory service command line tools like dsmod, dsquery and dsget. You can get syntax help by running 'dsquery \/?' (or dsmod,dsadd,dsget). There's a lot of help information so you'll probably want to pipe the results using More (dsquery\u2026","rel":"","context":"In &quot;Scripting&quot;","block_context":{"text":"Scripting","link":"https:\/\/jdhitsolutions.com\/blog\/category\/scripting\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":88,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/88\/powershell-parsing\/","url_meta":{"origin":7817,"position":3},"title":"Powershell Parsing","author":"Jeffery Hicks","date":"January 16, 2007","format":false,"excerpt":"In PowerShell, Get-WMIObject is a terrific cmdlet for remotely managing systems. If you have a text list of server or computer names, here's a quick method you could enumerate that list and do something to each server.foreach ($server in (Get-Content s:\\servers.txt)) {#skip blank lines if (($server).length -gt 0) { $server\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3019,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3019\/powershell-scripting-games-2013-impressions\/","url_meta":{"origin":7817,"position":4},"title":"PowerShell Scripting Games 2013 Impressions","author":"Jeffery Hicks","date":"May 13, 2013","format":false,"excerpt":"Now that the PowerShell Scripting Games for 2013 are well underway, I thought I'd share my thoughts and impressions on what I've seen. I'm very impressed with the number of entries and generally the quality is pretty good. But as a judge I see repeated items that bear comment. These\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/scriptinggames.org\/games-logo.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":8041,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8041\/get-group-policy-links-with-powershell\/","url_meta":{"origin":7817,"position":5},"title":"Get Group Policy Links with PowerShell","author":"Jeffery Hicks","date":"January 18, 2021","format":false,"excerpt":"I was chatting with my friend Gladys Kravitz about Group Policy reporting stuff recently,. and the discussion led me to dust off some old code I had for getting Group Policy links using PowerShell. The GroupPolicy module has a Set-GPLink command, but nothing that easily shows you what GPOs are\u2026","rel":"","context":"In &quot;Active Directory&quot;","block_context":{"text":"Active Directory","link":"https:\/\/jdhitsolutions.com\/blog\/category\/active-directory\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/01\/get-gpinherticance-1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/01\/get-gpinherticance-1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/01\/get-gpinherticance-1.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/01\/get-gpinherticance-1.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/01\/get-gpinherticance-1.png?resize=1050%2C600&ssl=1 3x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/7817","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=7817"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/7817\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=7817"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=7817"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=7817"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}