{"id":7700,"date":"2020-09-28T11:51:26","date_gmt":"2020-09-28T15:51:26","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=7700"},"modified":"2020-09-30T15:33:40","modified_gmt":"2020-09-30T19:33:40","slug":"active-directory-objects-and-the-powershell-pipeline","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7700\/active-directory-objects-and-the-powershell-pipeline\/","title":{"rendered":"Active Directory Objects and the PowerShell Pipeline"},"content":{"rendered":"\n<p>This article is something I've been meaning to write for sometime. As often as I tell people PowerShell is easy to use once you understand its core concepts, that isn't always the case.&nbsp; This is a problem my friend Gladys Kravitz brought to my attention some time ago.<\/p>\n\n\n\n<p>Like her, you probably have written a PowerShell function like this that accepts pipelined input.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Function Get-Foo {\n  [cmdletbinding()]\n  param(\n    [Parameter(Mandatory, ValueFromPipelinebyPropertyName)]\n    [string]$Name\n  )\n\n  Begin {}\n  Process {\n    Write-Host \"working on $Name\" -ForegroundColor Green\n  }\n  End {}\n}<\/code><\/pre>\n\n\n\n<p>This sample function looks at any incoming object, and assigns the Name property to the Name parameter. You can see the results with a simple test.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted lang:text mark:0 decode:true\">Get-Service bits, winrm | Get-Foo\nworking on bits\nworking on winrm\n<\/pre>\n\n\n\n<p>This function isn't doing anything other than displaying the value of the $Name parameter. Let's take a step forward.<\/p>\n\n\n\n<p>Here's a simple function to get the BITS service that takes pipeline input for the Computername.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Function Get-Bits {\n  [cmdletbinding()]\n  param(\n    [Parameter(Mandatory, ValueFromPipelineByPropertyName)]\n    [alias(\"Name\")]\n    [string]$Computername\n  )\n\n  Begin {}\n  Process {\n   Write-Host \"$Computername\" -ForegroundColor yellow\n   Get-service -Name bits -ComputerName $computername | Select-Object Machinename,Name,Status\n  }\n  End {}\n}<\/code><\/pre>\n\n\n\n<p>This works mostly as expected. I can specify a parameter value. I can also take input from the pipeline by property name.<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7701\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits.jpg\" alt=\"get-bits\" width=\"890\" height=\"1106\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits.jpg 890w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits-241x300.jpg 241w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits-824x1024.jpg 824w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits-768x954.jpg 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits-300x373.jpg 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits-850x1056.jpg 850w\" sizes=\"auto, (max-width: 890px) 100vw, 890px\" \/>But not with an Active Directory object.<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7702\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits-error.jpg\" alt=\"get-bits-error\" width=\"1023\" height=\"122\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits-error.jpg 1023w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits-error-300x36.jpg 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits-error-768x92.jpg 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits-error-850x101.jpg 850w\" sizes=\"auto, (max-width: 1023px) 100vw, 1023px\" \/>This is where Gladys started wondering what she was doing wrong. Clearly, the object has a Name property, because this variation works as expected.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1329\" height=\"295\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits-byname.jpg\" alt=\"get-bits-byname\" class=\"wp-image-7703\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits-byname.jpg 1329w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits-byname-300x67.jpg 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits-byname-1024x227.jpg 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits-byname-768x170.jpg 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits-byname-850x189.jpg 850w\" sizes=\"auto, (max-width: 1329px) 100vw, 1329px\" \/><\/figure>\n\n\n\n<p>It was time to see what was really happening. By the way, if you pipe the Get-ADComputer command to Get-Member, PowerShell will tell you the Name property is a String.<\/p>\n\n\n\n<p>To dive deeper, we turned to the Trace-Command cmdlet. You definitely want to read help and examples. In our case, we needed to see what PowerShell was doing with parameter binding.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1036\" height=\"618\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/trace-ADCommand.jpg\" alt=\"trace-ADCommand\" class=\"wp-image-7704\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/trace-ADCommand.jpg 1036w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/trace-ADCommand-300x180.jpg 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/trace-ADCommand-1024x611.jpg 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/trace-ADCommand-768x458.jpg 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/trace-ADCommand-850x507.jpg 850w\" sizes=\"auto, (max-width: 1036px) 100vw, 1036px\" \/><\/figure>\n\n\n\n<p>There's a lot to take in. As I scrolled down and got to the Get-Bits function, I noticed what PowerShell was doing with parameter binding for Computername.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"348\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/trace-ADCommand.-bindingjpg.jpg\" alt=\"trace-ADCommand.-bindingjpg\" class=\"wp-image-7705\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/trace-ADCommand.-bindingjpg.jpg 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/trace-ADCommand.-bindingjpg-300x102.jpg 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/trace-ADCommand.-bindingjpg-768x261.jpg 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/trace-ADCommand.-bindingjpg-850x289.jpg 850w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>PowerShell wasn't seeing a string. It was seeing an ADPropertyValueCollection, which it couldn't convert which results in an error.<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1017\" height=\"164\" class=\"alignnone size-full wp-image-7706\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/trace-ADCommand.-error.jpg\" alt=\"trace-ADCommand.-error\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/trace-ADCommand.-error.jpg 1017w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/trace-ADCommand.-error-300x48.jpg 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/trace-ADCommand.-error-768x124.jpg 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/trace-ADCommand.-error-850x137.jpg 850w\" sizes=\"auto, (max-width: 1017px) 100vw, 1017px\" \/>With this tidbit of information, I revised my sample Get-Bits function.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Function Get-Bits {\n#revised version\n  [cmdletbinding()]\n  param(\n    [Parameter(Mandatory, ValueFromPipelineByPropertyName)]\n    [alias(\"Name\")]\n    [object]$Computername\n  )\n\n  Begin {}\n  Process {\n    write-Host \"processing type $($computername.GetType().fullname)\" -ForegroundColor yellow\n    [Microsoft.ActiveDirectory.Management.ADPropertyValueCollection]::new($Computername)\n    switch ($computername.GetType().fullname) {\n      \"system.string\" {$cn = $Computername}\n      \"microsoft.activedirectory.management.adcomputer\" {$cn = $computername.name}\n      \"Microsoft.ActiveDirectory.Management.ADPropertyValueCollection\" {$cn = [Microsoft.ActiveDirectory.Management.ADPropertyValueCollection]::new($computername).name }\n      default { $cn = $Computername.computername }\n    }\n    write-Host \"working on $cn\" -fore Green\n    #  Get-service -Name bits -ComputerName $cn | Select-Object Machinename,Name,Status\n  }\n  End {}\n}<\/code><\/pre>\n\n\n\n<p>I need to pay attention the type of object I'm getting for Computername. I can't assume it will be a string. I want to verify my theory.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1324\" height=\"312\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/adproperty.jpg\" alt=\"adproperty\" class=\"wp-image-7707\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/adproperty.jpg 1324w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/adproperty-300x71.jpg 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/adproperty-1024x241.jpg 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/adproperty-768x181.jpg 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/adproperty-850x200.jpg 850w\" sizes=\"auto, (max-width: 1324px) 100vw, 1324px\" \/><\/figure>\n\n\n\n<p>Gladys, and most people, was assuming that the AD Object property was a simple thing, like a String. But clearly it is not. I can also infer from testing, that Select-Object plucks the property from collection and uses it to created the Selected.Microsoft.ActiveDirectory.Management.ADComputer object.<\/p>\n\n\n\n<p>Now that we know this, I can revise my sample function to better accommodate pipeline input from an Active Directory cmdlet. This will require the use of parameter sets.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Function Get-Bits {\n#with parameter sets\n  [cmdletbinding(DefaultParameterSetName = \"byString\")]\n  param(\n    [Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline, ParameterSetName = \"byString\")]\n    [alias(\"Name\")]\n    [string]$Computername,\n\n    [Parameter(ValueFromPipeline, ParameterSetName = \"byADComputer\")]\n    [Microsoft.ActiveDirectory.Management.ADComputer]$Computer\n  )\n\n  Begin {\n    Write-Verbose \"Starting $($myinvocation.mycommand)\"  \n  }\n  Process {\n  Write-Verbose \"Using parameter set $($pscmdlet.ParameterSetName)\"  \n    if ($PSCmdlet.ParameterSetName -eq \"byString\") {\n      $cn = $Computername\n    }\n    else {\n      Write-Verbose \"Getting the Name property\"\n      $cn = $Computer.Name\n    }\n    Write-Verbose \"Getting BITS service from $cn\"\n    Try {\n        Get-Service -Name bits -ComputerName $cn -ErrorAction Stop | \n        Select-Object Machinename, Name, Status\n    }\n    Catch {\n        Write-Warning \"Failed to get service status from $CN. $($_.exception.message)\"\n    }\n  }\n  End {\n    Write-Verbose \"Ending $($myinvocation.mycommand)\"  \n  }\n}<\/code><\/pre>\n\n\n\n<p>This version of the function will take pipeline input by property name for Computername, or the alias Name. Or, it will process an ADComputer object. In the Process block, I can get the proper computername value to pass on to Get-Service. This version gives me the PowerShell experience I'm expecting.<br><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7708\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits-rev-string.jpg\" alt=\"get-bits-rev-string\" width=\"1011\" height=\"1152\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits-rev-string.jpg 1011w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits-rev-string-263x300.jpg 263w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits-rev-string-899x1024.jpg 899w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits-rev-string-768x875.jpg 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits-rev-string-300x342.jpg 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits-rev-string-850x969.jpg 850w\" sizes=\"auto, (max-width: 1011px) 100vw, 1011px\" \/>And most importantly, using Get-ADComputer. My test domain has entries for non-existent computers.<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1138\" height=\"327\" class=\"alignnone size-full wp-image-7709\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/Get-bits-revised-ad.jpg\" alt=\"Get-bits-revised-ad\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/Get-bits-revised-ad.jpg 1138w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/Get-bits-revised-ad-300x86.jpg 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/Get-bits-revised-ad-1024x294.jpg 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/Get-bits-revised-ad-768x221.jpg 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/Get-bits-revised-ad-850x244.jpg 850w\" sizes=\"auto, (max-width: 1138px) 100vw, 1138px\" \/>Don't ask me why the AD cmdlets are written this way. They just are.\u00a0 If we want to incorporate them into our PowerShell work, we will need to make some accommodations. My sample Get-Bits function is just one example.<\/p>\n\n\n\n<p>At least Gladys knows she isn't going crazy and that there are solutions to her Active Directory scripting needs. I encourage you to try out Trace-Command. It might come in handy the next time you encounter a problem and want to cut down on the number of bruises on your forehead.<\/p>\n\n\n\n<p>As usual, comments and feedback are welcome.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article is something I&#8217;ve been meaning to write for sometime. As often as I tell people PowerShell is easy to use once you understand its core concepts, that isn&#8217;t always the case.&nbsp; This is a problem my friend Gladys Kravitz brought to my attention some time ago. Like her, you probably have written a&#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: Active Directory Objects and the #PowerShell Pipeline","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":[149,98,534,540],"class_list":["post-7700","post","type-post","status-publish","format-standard","hentry","category-active-directory","category-powershell","category-scripting","tag-activedirectory","tag-pipeline","tag-powershell","tag-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Active Directory Objects and the PowerShell Pipeline &#8226; The Lonely Administrator<\/title>\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\/powershell\/7700\/active-directory-objects-and-the-powershell-pipeline\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Active Directory Objects and the PowerShell Pipeline &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"This article is something I&#039;ve been meaning to write for sometime. As often as I tell people PowerShell is easy to use once you understand its core concepts, that isn&#039;t always the case.&nbsp; This is a problem my friend Gladys Kravitz brought to my attention some time ago. Like her, you probably have written a...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/7700\/active-directory-objects-and-the-powershell-pipeline\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-28T15:51:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-09-30T19:33:40+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits.jpg\" \/>\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=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7700\\\/active-directory-objects-and-the-powershell-pipeline\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7700\\\/active-directory-objects-and-the-powershell-pipeline\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Active Directory Objects and the PowerShell Pipeline\",\"datePublished\":\"2020-09-28T15:51:26+00:00\",\"dateModified\":\"2020-09-30T19:33:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7700\\\/active-directory-objects-and-the-powershell-pipeline\\\/\"},\"wordCount\":580,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7700\\\/active-directory-objects-and-the-powershell-pipeline\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/09\\\/get-bits.jpg\",\"keywords\":[\"ActiveDirectory\",\"Pipeline\",\"PowerShell\",\"Scripting\"],\"articleSection\":[\"Active Directory\",\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7700\\\/active-directory-objects-and-the-powershell-pipeline\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7700\\\/active-directory-objects-and-the-powershell-pipeline\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7700\\\/active-directory-objects-and-the-powershell-pipeline\\\/\",\"name\":\"Active Directory Objects and the PowerShell Pipeline &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7700\\\/active-directory-objects-and-the-powershell-pipeline\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7700\\\/active-directory-objects-and-the-powershell-pipeline\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/09\\\/get-bits.jpg\",\"datePublished\":\"2020-09-28T15:51:26+00:00\",\"dateModified\":\"2020-09-30T19:33:40+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7700\\\/active-directory-objects-and-the-powershell-pipeline\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7700\\\/active-directory-objects-and-the-powershell-pipeline\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7700\\\/active-directory-objects-and-the-powershell-pipeline\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/09\\\/get-bits.jpg\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/09\\\/get-bits.jpg\",\"width\":890,\"height\":1106},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7700\\\/active-directory-objects-and-the-powershell-pipeline\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Active Directory Objects and the PowerShell Pipeline\"}]},{\"@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":"Active Directory Objects and the PowerShell Pipeline &#8226; The Lonely Administrator","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\/powershell\/7700\/active-directory-objects-and-the-powershell-pipeline\/","og_locale":"en_US","og_type":"article","og_title":"Active Directory Objects and the PowerShell Pipeline &#8226; The Lonely Administrator","og_description":"This article is something I've been meaning to write for sometime. As often as I tell people PowerShell is easy to use once you understand its core concepts, that isn't always the case.&nbsp; This is a problem my friend Gladys Kravitz brought to my attention some time ago. Like her, you probably have written a...","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7700\/active-directory-objects-and-the-powershell-pipeline\/","og_site_name":"The Lonely Administrator","article_published_time":"2020-09-28T15:51:26+00:00","article_modified_time":"2020-09-30T19:33:40+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits.jpg","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":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7700\/active-directory-objects-and-the-powershell-pipeline\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7700\/active-directory-objects-and-the-powershell-pipeline\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Active Directory Objects and the PowerShell Pipeline","datePublished":"2020-09-28T15:51:26+00:00","dateModified":"2020-09-30T19:33:40+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7700\/active-directory-objects-and-the-powershell-pipeline\/"},"wordCount":580,"commentCount":1,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7700\/active-directory-objects-and-the-powershell-pipeline\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits.jpg","keywords":["ActiveDirectory","Pipeline","PowerShell","Scripting"],"articleSection":["Active Directory","PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/7700\/active-directory-objects-and-the-powershell-pipeline\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7700\/active-directory-objects-and-the-powershell-pipeline\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7700\/active-directory-objects-and-the-powershell-pipeline\/","name":"Active Directory Objects and the PowerShell Pipeline &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7700\/active-directory-objects-and-the-powershell-pipeline\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7700\/active-directory-objects-and-the-powershell-pipeline\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits.jpg","datePublished":"2020-09-28T15:51:26+00:00","dateModified":"2020-09-30T19:33:40+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7700\/active-directory-objects-and-the-powershell-pipeline\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/7700\/active-directory-objects-and-the-powershell-pipeline\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7700\/active-directory-objects-and-the-powershell-pipeline\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits.jpg","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-bits.jpg","width":890,"height":1106},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7700\/active-directory-objects-and-the-powershell-pipeline\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"Active Directory Objects and the PowerShell Pipeline"}]},{"@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":407,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/407\/is-that-folder-empty\/","url_meta":{"origin":7700,"position":0},"title":"Is That Folder Empty?","author":"Jeffery Hicks","date":"September 30, 2009","format":false,"excerpt":"In keeping with my recent trend of offering solutions based on PowerShell v2.0, here's a function I've revised to test if a folder is empty. I can't recall where I used the original function or if I ever did. But I came across it recently and decided to give it\u2026","rel":"","context":"In &quot;CommandLine&quot;","block_context":{"text":"CommandLine","link":"https:\/\/jdhitsolutions.com\/blog\/category\/commandline\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/09\/zrtn_003p5cb42026_tn.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":4305,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4305\/what-powershell-script-was-i-working-on\/","url_meta":{"origin":7700,"position":1},"title":"What PowerShell Script Was I Working On?","author":"Jeffery Hicks","date":"March 24, 2015","format":false,"excerpt":"Last week I shared a script for finding recently modified files in a given directory. In fact, it wouldn't be that difficult to find the last files I was working on and open them in the PowerShell ISE. Assuming my Get-RecentFile function is loaded it is a simple as this:\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":2330,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2330\/friday-fun-get-latest-powershell-scripts\/","url_meta":{"origin":7700,"position":2},"title":"Friday Fun: Get Latest PowerShell Scripts","author":"Jeffery Hicks","date":"May 18, 2012","format":false,"excerpt":"Probably like many of you I keep almost all of my scripts in a single location. I'm also usually working on multiple items at the same time. Some times I have difficult remembering the name of a script I might have been working on a few days ago that I\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/05\/get-latestscript-300x133.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":8693,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8693\/exporting-powershell-functions-to-files\/","url_meta":{"origin":7700,"position":3},"title":"Exporting PowerShell Functions to Files","author":"Jeffery Hicks","date":"December 3, 2021","format":false,"excerpt":"When I write a PowerShell module, it typically includes more than one export function. Where you store your module functions is a great discussion topic and I don't think there is necessarily one best practice for everyone. I think it might depend on the number and complexity of the functions.\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\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/export-function3.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/export-function3.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/export-function3.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/12\/export-function3.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":840,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/840\/pipelines-consoles-and-hosts\/","url_meta":{"origin":7700,"position":4},"title":"Pipelines, Consoles and Hosts","author":"Jeffery Hicks","date":"August 19, 2010","format":false,"excerpt":"I continue to come across a particular topic in discussion forums that causes many PowerShell beginners a lot of headaches and more than a little frustration. I know I've written about this before and I'm sure I'll cover it again, but when writing anything in PowerShell that you see in\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\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/08\/write-demo.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":7786,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/7786\/open-up-wide-with-powershell\/","url_meta":{"origin":7700,"position":5},"title":"Open Up Wide with PowerShell","author":"Jeffery Hicks","date":"October 19, 2020","format":false,"excerpt":"A few weeks ago, an Iron Scripter PowerShell scripting challenge was posted. The challenge involved wide directory listings. Which always makes me think \"open wide\", which leads me to \"Open Up Wide\" by Chase. (I used to play trumpet and Chase was THE band back in the day). Anyway, solving\u2026","rel":"","context":"In &quot;Scripting&quot;","block_context":{"text":"Scripting","link":"https:\/\/jdhitsolutions.com\/blog\/category\/scripting\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-1.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-1.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-1.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/10\/sw-1.png?resize=1400%2C800&ssl=1 4x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/7700","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=7700"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/7700\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=7700"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=7700"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=7700"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}