{"id":1483,"date":"2011-05-31T08:52:10","date_gmt":"2011-05-31T12:52:10","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=1483"},"modified":"2011-05-31T08:52:10","modified_gmt":"2011-05-31T12:52:10","slug":"test-port-2-0","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1483\/test-port-2-0\/","title":{"rendered":"Test Port 2.0"},"content":{"rendered":"<p>A few years ago I updated a PowerShell script I came across to scan a computer for open ports. My initial revision was aimed at making it more pipeline friendly in PowerShell v1.0. I recently needed to use the function for a project and realized it could benefit from a 2.0 upgrade.<!--more--><\/p>\n<p>The new function uses a valid verb in the name, \"Test\", as opposed to the old \"Scan\". I was also able to take advantage of cmdletbinding, New-Object and Try\/Catch. Not to mention comment based help, which is in the download file.<\/p>\n<p>[cc lang=\"PowerShell\"]<br \/>\nFunction Test-Port {<\/p>\n<p>[cmdletbinding(SupportsShouldProcess=$True,ConfirmImpact=\"Low\")]<\/p>\n<p>Param(<br \/>\n[Parameter(Position=0,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]<br \/>\n[ValidateNotNullorEmpty()]<br \/>\n[string[]]$Computername=$env:computername,<br \/>\n[array]$Ports=@(\"21\",\"22\",\"23\",\"25\",\"80\",\"443\",\"3389\")<br \/>\n)<\/p>\n<p>Begin {<br \/>\n  #set values for Write-Progress<br \/>\n  Write-Verbose \"$(Get-Date) Starting $($myinvocation.mycommand)\"<br \/>\n  Write-Verbose \"$(Get-Date) Scannning for ports $($ports  -as [string])\"<br \/>\n  $activity=\"Port Scan\"<br \/>\n}<\/p>\n<p>Process {<\/p>\n<p> Foreach ($computer in $computername) {<\/p>\n<p> #whatif<br \/>\n if ($pscmdlet.ShouldProcess($($computer.ToUpper()))) {<br \/>\n  $status=\"Scanning $computer\"<br \/>\n  Write-Verbose \"$(Get-Date) $status\"<br \/>\n  $i=0<\/p>\n<p>       foreach ($port in $ports) {<br \/>\n       $i++<br \/>\n        Write-Progress -Activity $activity -status $status `<br \/>\n        -currentoperation \"port $port\" -percentcomplete (($i\/$ports.count)*100)<\/p>\n<p>        Try {<br \/>\n            #create the TCPClient object<br \/>\n            $tcp=New-Object System.Net.Sockets.TcpClient($computer, $port) -ErrorAction Stop<br \/>\n        }<br \/>\n        Catch {<br \/>\n            Write-Verbose \"$(Get-Date) Connection refused\"<br \/>\n        }<br \/>\n        if ($tcp.client.connected)<br \/>\n        {<br \/>\n            [string]$rep=$tcp.client.RemoteEndPoint<br \/>\n            [string]$ip=$rep.substring(0,$rep.indexof(\":\"))<\/p>\n<p>            $PortOpen=$True<br \/>\n            $TTL=$($tcp.client.ttl)<br \/>\n            $RemoteIP=$ip<\/p>\n<p>        }<br \/>\n        else<br \/>\n        {<br \/>\n            Write-Verbose \"$(Get-Date) $($computer.ToUpper()) not open on port: $port\"<br \/>\n            $PortOpen=$False<br \/>\n            $TTL=-1<br \/>\n            $RemoteIP=$Null<br \/>\n        }  #end Else<\/p>\n<p>            #disconnect the socket connection if open<br \/>\n            if ($PortOpen)<br \/>\n            {<br \/>\n                Write-Verbose \"$(Get-Date) Disconnecting from $($computer.ToUpper())\"<br \/>\n                $tcp.client.disconnect($False)<br \/>\n            }<\/p>\n<p>            #write a custom object to the pipeline<br \/>\n            New-Object -TypeName PSObject -Property @{<br \/>\n              Computername=$Computer.ToUpper()<br \/>\n              Port=$Port<br \/>\n              Open=$PortOpen<br \/>\n              TTL=$TTL<br \/>\n              RemoteIP=$RemoteIP<\/p>\n<p>            }<\/p>\n<p>        } #end foreach $port<\/p>\n<p>        #dispose and disconnect<br \/>\n        if ($tcp)<br \/>\n        {<br \/>\n            $tcp.close()<br \/>\n        }<br \/>\n     } #if shouldprocess<br \/>\n     } #foreach $computer<br \/>\n} #end process<\/p>\n<p>End {<br \/>\n    Write-Progress -Activity $activity -status \"Complete\" -Completed<br \/>\n    Write-Verbose \"$(Get-Date) Ending $($myinvocation.mycommand)\"<br \/>\n }#end<\/p>\n<p>} #end function<br \/>\n[\/cc]<\/p>\n<p>The function supports -Whatif and -Confirm since scanning ports could be time consuming and something you may want to verify before you start scanning a large number of computers. You can pipe computer names to the function but the function will scan the same array of ports. The default array is 21, 22,23,25,80,443 and 3389. These are TCP ports by the way.  <\/p>\n<p>The function uses the .NET System.Net.Sockets.TcpClient class to open the port on the coimputer. <\/p>\n<p>[cc lang=\"PowerShell\"]<br \/>\nTry {<br \/>\n            #create the TCPClient object<br \/>\n            $tcp=New-Object System.Net.Sockets.TcpClient($computer, $port) -ErrorAction Stop<br \/>\n        }<br \/>\n[\/cc]<\/p>\n<p>If the connection is made, the function retrieves some information and writes a custom object to the pipeline.<\/p>\n<p>[cc lang=\"Powershell\"]<br \/>\n#write a custom object to the pipeline<br \/>\nNew-Object -TypeName PSObject -Property @{<br \/>\n  Computername=$Computer.ToUpper()<br \/>\n  Port=$Port<br \/>\n  Open=$PortOpen<br \/>\n  TTL=$TTL<br \/>\n  RemoteIP=$RemoteIP<br \/>\n }<br \/>\n[\/cc]<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/05\/test-port.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/05\/test-port-300x126.png\" alt=\"\" title=\"test-port\" width=\"300\" height=\"126\" class=\"aligncenter size-medium wp-image-1487\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/05\/test-port-300x126.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/05\/test-port.png 943w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Because the function takes advantage of the pipeline, you can run an expression like this:<\/p>\n<p>[cc lang=\"DOS\"]<br \/>\nPS C:\\> get-content computers.txt | Test-Port -port 80 | Where {$_.Open} | Out-File Open80.txt<br \/>\n[\/cc]<\/p>\n<p>This one line command will test all the computers listed in computer.txt for port 80 and save the results where true to Open80.txt. The function uses Write-Progress to provide feedback on what is being scanned. Write-Progress is not used as often as it could be and I think it's because there aren't enough practical examples, so I'm hoping this will help.<\/p>\n<p>Enjoy and let me know what you think.<\/p>\n<p>Download <a href='http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/05\/Test-Port.txt' target='_blank'>Test-Port<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few years ago I updated a PowerShell script I came across to scan a computer for open ports. My initial revision was aimed at making it more pipeline friendly in PowerShell v1.0. I recently needed to use the function for a project and realized it could benefit from a 2.0 upgrade.<\/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":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[75,8],"tags":[224,292,291,534,540,236],"class_list":["post-1483","post","type-post","status-publish","format-standard","hentry","category-powershell-v2-0","category-scripting","tag-function","tag-networking","tag-port","tag-powershell","tag-scripting","tag-write-progress"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Test Port 2.0 &#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\/scripting\/1483\/test-port-2-0\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Test Port 2.0 &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"A few years ago I updated a PowerShell script I came across to scan a computer for open ports. My initial revision was aimed at making it more pipeline friendly in PowerShell v1.0. I recently needed to use the function for a project and realized it could benefit from a 2.0 upgrade.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/scripting\/1483\/test-port-2-0\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2011-05-31T12:52:10+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/05\/test-port-300x126.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=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1483\\\/test-port-2-0\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1483\\\/test-port-2-0\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Test Port 2.0\",\"datePublished\":\"2011-05-31T12:52:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1483\\\/test-port-2-0\\\/\"},\"wordCount\":553,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1483\\\/test-port-2-0\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2011\\\/05\\\/test-port-300x126.png\",\"keywords\":[\"Function\",\"networking\",\"port\",\"PowerShell\",\"Scripting\",\"Write-progress\"],\"articleSection\":[\"PowerShell v2.0\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1483\\\/test-port-2-0\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1483\\\/test-port-2-0\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1483\\\/test-port-2-0\\\/\",\"name\":\"Test Port 2.0 &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1483\\\/test-port-2-0\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1483\\\/test-port-2-0\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2011\\\/05\\\/test-port-300x126.png\",\"datePublished\":\"2011-05-31T12:52:10+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1483\\\/test-port-2-0\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1483\\\/test-port-2-0\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1483\\\/test-port-2-0\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2011\\\/05\\\/test-port.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2011\\\/05\\\/test-port.png\",\"width\":\"943\",\"height\":\"398\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1483\\\/test-port-2-0\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell v2.0\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell-v2-0\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Test Port 2.0\"}]},{\"@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":"Test Port 2.0 &#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\/scripting\/1483\/test-port-2-0\/","og_locale":"en_US","og_type":"article","og_title":"Test Port 2.0 &#8226; The Lonely Administrator","og_description":"A few years ago I updated a PowerShell script I came across to scan a computer for open ports. My initial revision was aimed at making it more pipeline friendly in PowerShell v1.0. I recently needed to use the function for a project and realized it could benefit from a 2.0 upgrade.","og_url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1483\/test-port-2-0\/","og_site_name":"The Lonely Administrator","article_published_time":"2011-05-31T12:52:10+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/05\/test-port-300x126.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":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1483\/test-port-2-0\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1483\/test-port-2-0\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Test Port 2.0","datePublished":"2011-05-31T12:52:10+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1483\/test-port-2-0\/"},"wordCount":553,"commentCount":2,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1483\/test-port-2-0\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/05\/test-port-300x126.png","keywords":["Function","networking","port","PowerShell","Scripting","Write-progress"],"articleSection":["PowerShell v2.0","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/1483\/test-port-2-0\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1483\/test-port-2-0\/","url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1483\/test-port-2-0\/","name":"Test Port 2.0 &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1483\/test-port-2-0\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1483\/test-port-2-0\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/05\/test-port-300x126.png","datePublished":"2011-05-31T12:52:10+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1483\/test-port-2-0\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/1483\/test-port-2-0\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1483\/test-port-2-0\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/05\/test-port.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/05\/test-port.png","width":"943","height":"398"},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1483\/test-port-2-0\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell v2.0","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-v2-0\/"},{"@type":"ListItem","position":2,"name":"Test Port 2.0"}]},{"@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":3036,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3036\/test-64-bit-operating-system\/","url_meta":{"origin":1483,"position":0},"title":"Test 64-Bit Operating System","author":"Jeffery Hicks","date":"May 16, 2013","format":false,"excerpt":"One of the great features of PowerShell is how much you can get from a relatively simple one line command. For example. you might want to test if a computer is running a 64-bit operating system. You can find out with a command as simple as this. PS C:\\> (get-wmiobject\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"osarchitecture-fail","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/osarchitecture-fail-1024x298.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/osarchitecture-fail-1024x298.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/osarchitecture-fail-1024x298.png?resize=525%2C300 1.5x"},"classes":[]},{"id":2935,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2935\/get-ciminstance-from-powershell-2-0\/","url_meta":{"origin":1483,"position":1},"title":"Get CIMInstance from PowerShell 2.0","author":"Jeffery Hicks","date":"April 10, 2013","format":false,"excerpt":"I love the new CIM cmdlets in PowerShell 3.0. Querying WMI is a little faster because the CIM cmdlets query WMI using the WSMAN protocol instead of DCOM. The catch is that remote computers must be running PowerShell 3 which includes the latest version of the WSMAN protocol and the\u2026","rel":"","context":"In &quot;Powershell 3.0&quot;","block_context":{"text":"Powershell 3.0","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-3-0\/"},"img":{"alt_text":"get-ciminstance-error","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-ciminstance-error-300x145.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":4572,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4572\/what-are-you\/","url_meta":{"origin":1483,"position":2},"title":"What Are You?","author":"Jeffery Hicks","date":"October 23, 2015","format":false,"excerpt":"Here's a quick way to tell whether a given machine is real or not: check the Win32_Baseboard class. You can use either Get-WmiObject or Get-CimInstance. Notice the results from a few physical machines. Now see the result when querying a Hyper-V virtual machine: I don't have any VMware available so\u2026","rel":"","context":"In &quot;Hyper-V&quot;","block_context":{"text":"Hyper-V","link":"https:\/\/jdhitsolutions.com\/blog\/category\/hyper-v\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":7700,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7700\/active-directory-objects-and-the-powershell-pipeline\/","url_meta":{"origin":1483,"position":3},"title":"Active Directory Objects and the PowerShell Pipeline","author":"Jeffery Hicks","date":"September 28, 2020","format":false,"excerpt":"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.\u00a0 This is a problem my friend Gladys Kravitz brought to my attention some time ago. Like her,\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\/2020\/09\/Get-bits-revised-ad.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/Get-bits-revised-ad.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/Get-bits-revised-ad.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/Get-bits-revised-ad.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/Get-bits-revised-ad.jpg?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":1355,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1355\/get-comon-data\/","url_meta":{"origin":1483,"position":4},"title":"Get Common Data","author":"Jeffery Hicks","date":"April 18, 2011","format":false,"excerpt":"While judging entries in this year's Scripting Games I realized there were some common properties that were repeatedly used. This got me thinking about a simple way to retrieve that information with a single command Then you could access the data values from within your script. I've put together a\u2026","rel":"","context":"In &quot;PowerShell v2.0&quot;","block_context":{"text":"PowerShell v2.0","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-v2-0\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1532,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1532\/get-local-administrators-with-wmi-and-powershell\/","url_meta":{"origin":1483,"position":5},"title":"Get Local Administrators with WMI and PowerShell","author":"Jeffery Hicks","date":"July 1, 2011","format":false,"excerpt":"Earlier this week I was helping someone out on a problem working with the local administrators group. There are a variety of ways to enumerate the members of a local group. The code he was using involved WMI. I hadn't really worked with the WMI approach in any great detail\u2026","rel":"","context":"In &quot;PowerShell v2.0&quot;","block_context":{"text":"PowerShell v2.0","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-v2-0\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1483","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=1483"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1483\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=1483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=1483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=1483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}