{"id":3763,"date":"2014-03-27T15:41:21","date_gmt":"2014-03-27T19:41:21","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=3763"},"modified":"2014-03-27T15:41:21","modified_gmt":"2014-03-27T19:41:21","slug":"more-fun-with-string-properties","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3763\/more-fun-with-string-properties\/","title":{"rendered":"More Fun with String Properties"},"content":{"rendered":"<p>The other day I posted an article about <a title=\"Convert a String to a PowerShell Property Name\" href=\"http:\/\/jdhitsolutions.com\/blog\/2014\/03\/convert-a-string-to-a-powershell-property-name\/\" target=\"_blank\">converting string properties<\/a> that you might get from running a command line tool into a PowerShell named property. I was continuing to experiment with it. Here's some code on how I could use it.<\/p>\n<pre class=\"lang:ps decode:true\">$raw = qprocess\r\n$properties = $raw[0] -split \"\\s{2,}\" | Convert-StringProperty \r\n$raw | select -Skip 1 | foreach {\r\n #split each line\r\n $data = $_ -split \"\\s{2,}\"\r\n $hash=[ordered]@{}\r\n for ($i=0;$i -lt $properties.count;$i++) {\r\n   $hash.Add($properties[$i],$data[$i])\r\n }\r\n [pscustomobject]$hash\r\n}<\/pre>\n<p>I end up with output like this:<\/p>\n<pre class=\"lang:batch decode:true\">Username    : &gt;jeff\r\nSessionname : console\r\nId          : 1\r\nPid         : 3044\r\nImage       : conhost.exe\r\n\r\nUsername    : &gt;jeff\r\nSessionname : console\r\nId          : 1\r\nPid         : 4848\r\nImage       : chrome.exe<\/pre>\n<p>It would be nice to clean up the values and remove non word characters like the \"&lt;\". But I wouldn't want to remove the period from the image property. So I came up with this:<\/p>\n<pre class=\"lang:ps decode:true\">$raw = qprocess\r\n$properties = $raw[0] -split \"\\s{2,}\" | Convert-StringProperty \r\n$raw | select -Skip 1 | foreach {\r\n #split each line\r\n $data = $_ -split \"\\s{2,}\"\r\n $hash=[ordered]@{}\r\n for ($i=0;$i -lt $properties.count;$i++) {\r\n   #remove any &lt; &gt; or # characters from data value\r\n   $hash.Add($properties[$i],($data[$i] -replace \"[&gt;&lt;#]\",\"\"))\r\n }\r\n [pscustomobject]$hash\r\n}<\/pre>\n<p>Each data element is cleaned up using the Replace operator to replace any character in the regular expression pattern with nothing. Then I started experimenting with command line output that display as a series of lines like ipconfig \/displaydns. First, I have to decide what to process so I want to get all lines that have '. . .' in it.<\/p>\n<pre class=\"lang:ps decode:true\">$raw = ipconfig \/displaydns | where {$_ -match \"\\.\\s\"}<\/pre>\n<p>Looking at the output I can see that basically I get an \"object\" for every group of 5 lines.<\/p>\n<pre class=\"lang:ps decode:true\">$group = 5\r\nfor ($i=0;$i -lt $raw.count;$i+=($group+1)) {\r\n   $raw[$i..($i+$group)] | foreach -begin {\r\n  $hash=[ordered]@{}\r\n  } -process {\r\n    #split on the first : into 2 strings\r\n    $split = $_ -split \":\",2\r\n    $prop = $split[0] | Convert-StringProperty\r\n    $value = $split[1]\r\n    $hash.add($prop,$value)\r\n  } -end {\r\n     [pscustomobject]$hash\r\n  }\r\n}<\/pre>\n<p>This code counts in groups of 5 and gets each group of elements using a range of index numbers. Each line in the range is then split into 2 strings on the first : character. The first item will be the property name which is converted into a string property and the second item will be the data. This gives me a custom object:<\/p>\n<pre class=\"lang:batch decode:true\">RecordName  :  ec2-50-16-209-174.compute-1.amazonaws.com\r\nRecordType  :  1\r\nTimeToLive  :  19610\r\nDataLength  :  4\r\nSection     :  Answer\r\nAhostRecord :  50.16.209.174\r\n\r\nRecordName :  13.30.16.172.in-addr.arpa.\r\nRecordType :  12\r\nTimeToLive :  86400\r\nDataLength :  8\r\nSection    :  Answer\r\nPtrRecord  :  chi-core01.globomantics.local<\/pre>\n<p>Which lead to the next challenge. The last line is being interpreted as two separate properties which is a bit of a mess. So I need a way to rename that line. Or actually any line. Maybe instead of TimeToLive I want to use TTL. Here's the next step.<\/p>\n<pre class=\"lang:ps decode:true\">$replaceHash=@{5=\"Record\";2=\"TTL\"}\r\n\r\n$raw = ipconfig \/displaydns | where {$_ -match \"\\.\\s\"}\r\n$group = 5\r\n\r\nfor ($i=0;$i -lt $raw.count;$i+=($group+1)) {\r\n   $raw[$i..($i+$group)] | foreach -begin {\r\n     $hash=[ordered]@{}\r\n     #define an process counter\r\n     $k=0\r\n  } -process {\r\n    $split = $_ -split \":\",2\r\n    if ($replaceHash.keys -contains $k) {\r\n      #get replacement property name from hash table\r\n      $prop = $replaceHash.Item($k)\r\n    }\r\n    else {\r\n        #convert existing property name\r\n        $prop = $split[0] | Convert-StringProperty\r\n    }\r\n    $value = $split[1]\r\n    $hash.add($prop,$value)\r\n    #increment the property counter\r\n    $k++\r\n  } -end {\r\n     [pscustomobject]$hash\r\n  }\r\n}<\/pre>\n<p>I have to know in advance what line number each property will be on. But since I do I'll create a hashtable that uses the line number (starting at 0) as the key. The hashtable value will be the replacement property name. In my process scriptblock I'm keeping track of how many lines I've worked on. If the counter matches a key in the hashtable I do a replacement. Now I get this:<\/p>\n<pre class=\"lang:ps decode:true\">RecordName :  ec2-50-16-209-174.compute-1.amazonaws.com\r\nRecordType :  1\r\nTTL        :  19044\r\nDataLength :  4\r\nSection    :  Answer\r\nRecord     :  50.16.209.174\r\n\r\nRecordName :  13.30.16.172.in-addr.arpa.\r\nRecordType :  12\r\nTTL        :  86400\r\nDataLength :  8\r\nSection    :  Answer\r\nRecord     :  chi-core01.globomantics.local<\/pre>\n<p>At this point I recognize that I have another repeatable code that I could turn this into a function.<\/p>\n<pre class=\"lang:ps decode:true crayon-selected\">Function Convert-CLIOutput {\r\n\r\n&lt;#\r\n.SYNOPSIS\r\nConvert CLI-based tool output to PowerShell object\r\n.DESCRIPTION\r\nThis command will process output from a command line tool and turn it into\r\nPowerShell pipeline output. It relies on the Convert-StringProperty function.\r\nThis command works best with tabular output where column headings are separated\r\nby at least 2 spaces.\r\n\r\nYou can use list oriented data but you must tell the command you are processing\r\na list as well as tell it how many lines are grouped together to form a new\r\nobject.\r\n\r\nBy default, the command will remove any non-word characters from the data such as\r\n&gt; or # using a regular expression pattern for -Cleanup. Use -NoCleanup if you want\r\nthe data as it appears in the command line tool output. NoCleanup will take\r\nprecedence over Cleanup.\r\n\r\nSometimes properties aren't what you want so you can use a custom hashtable\r\nto specify replacement values. The key will the number of the property starting\r\nat 1. In a table count left to right. In a list count top down. The value is \r\nthe replacement property value.\r\n\r\nYou cannot pipe anything into this command.\r\n.PARAMETER Delimiter\r\nThe delimiter for property names in the CLI output. The default is a space.\r\nThis command uses Convert-StringProperty to convert a string like \r\n\"Internet address\" into a \"InternetAddress\"\r\n.PARAMETER ReplaceHash\r\nA hashtable of replacement property values.  The key will the number of the \r\nproperty starting at 1. In a table count left to right. In a list count top \r\ndown. The value is the replacement property value. See examples.\r\n.PARAMETER List\r\nSpecify that the input is formatted as a list\r\n.PARAMETER Group\r\nThe number of lines that will be grouped together to define a single set of \r\n.PARAMETER LineDelimiter\r\nWhen processing line output, this will specify the delimiter separating the\r\nproperty from the value. The default is the colon.\r\nobject properties.\r\n.PARAMETER Cleanup\r\nA regular expression pattern of characters to clean up from data output. The\r\ndefault is [&lt;&gt;$#].\r\n.EXAMPLE\r\nPS C:\\&gt; $raw = netstat -n | select -skip 3\r\nPS C:\\&gt; convert-clioutput $raw | where {$_.state -match \"Time_Wait\"}\r\n\r\nProto              LocalAddress                     ForeignAddress                   State                           \r\n-----              ------------                     --------------                   -----                           \r\nTCP                172.16.10.127:50115              172.16.10.86:80                 TIME_WAIT \r\n\r\n.EXAMPLE\r\nPS C:\\&gt; $raw = ipconfig \/displaydns | where {$_ -match \"\\.\\s\"}\r\nPS C:\\&gt; Convert-CLIOutput $raw -list -group 6 -ReplaceHash @{6=\"Record\"} -NoCleanup\r\n\r\nRecordName :  ec2-54-221-234-232.compute-1.amazonaws.com\r\nRecordType :  1\r\nTimeToLive :  1277\r\nDataLength :  4\r\nSection    :  Answer\r\nRecord     :  54.221.234.232\r\n\r\nRecordName :  13.30.16.172.in-addr.arpa.\r\nRecordType :  12\r\nTimeToLive :  86400\r\nDataLength :  8\r\nSection    :  Answer\r\nRecord     :  chi-core01.globomantics.local\r\n...\r\n\r\nThe output from Ipconfig \/displaydns is presented in a list. In this example, the \r\noutput for each entry is grouped in 6 lines. The replacement hash table replaces\r\nthe property for the 6th line with a different value. The expression is using the\r\n-NoCleanup parameter so that record names are not stripped of periods and dashes.\r\n.EXAMPLE\r\nPS C:\\&gt; Convert-CLIOutput (quser) -ReplaceHash @{1=\"User\";2=\"Session\"} \r\n\r\nUser      : jeff\r\nSession   : console\r\nId        : 1\r\nState     : Active\r\nIdleTime  : none\r\nLogonTime : 3262014345PM\r\n\r\nThis command takes table output from quser.exe and turns it into an object using\r\na hashtable of replacement values.\r\n#&gt;\r\n\r\n[cmdletbinding(DefaultParameterSetName=\"Table\")]\r\nParam(\r\n[Parameter(Position=0)]\r\n$InputObject,\r\n[string]$Delimiter=\" \",\r\n[switch]$NoCleanup,\r\n[hashtable]$ReplaceHash,\r\n[regex]$Cleanup=\"[&lt;&gt;#?]\",\r\n[Parameter(ParameterSetName=\"List\")]\r\n[switch]$List,\r\n[Parameter(ParameterSetName=\"List\",Mandatory=$True,\r\nHelpMessage=\"How many lines in a group?\")]\r\n[int]$Group,\r\n[Parameter(ParameterSetName=\"List\")]\r\n[ValidateNotNullorEmpty()]\r\n[string]$LineDelimiter=\":\"\r\n)\r\n\r\nBegin {\r\n    Write-Verbose \"Starting $($MyInvocation.Mycommand)\"\r\n    Write-Verbose \"Using parameter set $($PSCmdlet.ParameterSetName)\"\r\n    [regex]$rx=\"\\s{2,}\"\r\n} #Begin\r\nProcess {\r\n\r\n    If ($PSCmdlet.ParameterSetName -eq \"Table\") {\r\n\r\n        Write-Verbose \"Processing property names\"\r\n        $properties = $rx.Split($InputObject[0].trim()) | Convert-StringProperty -Delimiter $delimiter\r\n\r\n        Write-Verbose \"Converting data to objects\"\r\n        for ($i=1;$i -lt $inputObject.count; $i++) {\r\n          $splitData = $rx.split($inputobject[$i].Trim())\r\n          #create an object for each entry\r\n          $hash = [ordered]@{}\r\n          for ($j=0;$j -lt $properties.count;$j++) {\r\n             if ($NoCleanup) {\r\n                 $value = $splitData[$j]\r\n             }\r\n             else {\r\n                #add each data element stripped of any non word characters like &lt; or #\r\n                $value = $splitData[$j] -replace $Cleanup,''\r\n            }\r\n\r\n            #replace properties with values from hashtable\r\n            if ($ReplaceHash.keys -contains ($j+1)) {\r\n\r\n               $newProperty = $ReplaceHash.Item($j+1)\r\n               Write-verbose \"Using replacement property $newproperty\"\r\n            }\r\n            else {\r\n               $newProperty = $properties[$j]\r\n            }\r\n            #add the property key and value to the hashtable\r\n            $hash.Add($newProperty,$value)\r\n          } #for\r\n            #Write a custom object to the pipeline\r\n            [pscustomobject]$hash\r\n        } #for\r\n    } #if table\r\n    else {\r\n      for ($i=0;$i -lt $inputobject.count;$i+=$group) {\r\n       $inputobject[$i..($i+($group-1))] | foreach -begin {\r\n         $hash=[ordered]@{}\r\n         #define an process counter\r\n         $k=1\r\n      } -process {\r\n        #split the line on the first line delimiter.\r\n        $split = $_ -split $LineDelimiter,2\r\n        if ($replaceHash.keys -contains $k) {\r\n          #get replacement property name from hash table if processing the \r\n          #matching line number\r\n          $prop = $replaceHash.Item($k)\r\n        }\r\n        else {\r\n            #convert existing property name\r\n            $prop = $split[0] | Convert-StringProperty -Delimiter $delimiter\r\n        }\r\n        if ($NoCleanup) {\r\n            $value = $split[1]\r\n        }\r\n        else {\r\n              #add each data element stripped of any non word characters like &lt; or #\r\n              $value = $split[1] -replace $Cleanup,''\r\n         }\r\n\r\n        $hash.add($prop,$value)\r\n        #increment the property counter\r\n        $k++\r\n       } #process\r\n        #Write a custom object to the pipeline\r\n        [pscustomobject]$hash\r\n    } #for\r\n    } #else   \r\n\r\n} #process\r\n\r\nEnd { \r\n    Write-Verbose -Message \"Ending $($MyInvocation.Mycommand)\"\r\n}\r\n} #end function<\/pre>\n<p>This function relies on Convert-StringProperty. At some point I should package this and few other things I have into a module. But for now you'll have to make sure the other function is loaded into your shell. The default processing assumes you have tabular output like you get from arp -a. You can specify input that is in a list but then you also need to specify how many lines are grouped together. You can also specify a hashtable of replacement property names for either input type. To keep things easier, the hashtable keys start counting at 1.<\/p>\n<p>You can't pipe into the command. You have to specify the input like this:<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/03\/convert-clioutput-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-3765\" alt=\"convert-clioutput-1\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/03\/convert-clioutput-1-1024x633.png\" width=\"474\" height=\"293\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/03\/convert-clioutput-1-1024x633.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/03\/convert-clioutput-1-300x185.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/03\/convert-clioutput-1.png 1150w\" sizes=\"auto, (max-width: 474px) 100vw, 474px\" \/><\/a><\/p>\n<p>Here are some other examples using tabular output including a property rename.<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/03\/convert-clioutput-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-3766\" alt=\"convert-clioutput-2\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/03\/convert-clioutput-2-1024x693.png\" width=\"474\" height=\"320\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/03\/convert-clioutput-2-1024x693.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/03\/convert-clioutput-2-300x203.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/03\/convert-clioutput-2.png 1150w\" sizes=\"auto, (max-width: 474px) 100vw, 474px\" \/><\/a><\/p>\n<p>Using my IPCONFIG example from earlier, here's I can do it with my new function.<\/p>\n<pre class=\"lang:ps decode:true\">$raw = ipconfig \/displaydns | where {$_ -match \"\\.\\s\"}\r\nConvert-CLIOutput $raw -ReplaceHash @{3=\"TTL\";6=\"Record\"} -list -group 6 | Out-GridView -Title DisplayDNS<\/pre>\n<p>In the grid view I can further filter or sort.<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/03\/convert-clioutput-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-3767\" alt=\"convert-clioutput-3\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/03\/convert-clioutput-3-300x111.png\" width=\"300\" height=\"111\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/03\/convert-clioutput-3-300x111.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/03\/convert-clioutput-3.png 804w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>One remaining issue here is that everything is a string. But in that regard it really isn't that much different than when you import a CSV file. I guess this gives me something else to work on. In the meantime, try this out and let me know what you think.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The other day I posted an article about converting string properties that you might get from running a command line tool into a PowerShell named property. I was continuing to experiment with it. Here&#8217;s some code on how I could use it. $raw = qprocess $properties = $raw[0] -split &#8220;\\s{2,}&#8221; | Convert-StringProperty $raw | select&#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":"Fresh from the blog: More Fun with String Properties  in #PowerShell http:\/\/wp.me\/p1nF6U-YH","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":[72,4,8],"tags":[534,250,540],"class_list":["post-3763","post","type-post","status-publish","format-standard","hentry","category-commandline","category-powershell","category-scripting","tag-powershell","tag-regular-expressions","tag-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>More Fun with String Properties &#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\/3763\/more-fun-with-string-properties\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"More Fun with String Properties &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"The other day I posted an article about converting string properties that you might get from running a command line tool into a PowerShell named property. I was continuing to experiment with it. Here&#039;s some code on how I could use it. $raw = qprocess $properties = $raw[0] -split &quot;s{2,}&quot; | Convert-StringProperty $raw | select...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/3763\/more-fun-with-string-properties\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2014-03-27T19:41:21+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/03\/convert-clioutput-1-1024x633.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=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3763\\\/more-fun-with-string-properties\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3763\\\/more-fun-with-string-properties\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"More Fun with String Properties\",\"datePublished\":\"2014-03-27T19:41:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3763\\\/more-fun-with-string-properties\\\/\"},\"wordCount\":574,\"commentCount\":5,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3763\\\/more-fun-with-string-properties\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2014\\\/03\\\/convert-clioutput-1-1024x633.png\",\"keywords\":[\"PowerShell\",\"Regular Expressions\",\"Scripting\"],\"articleSection\":[\"CommandLine\",\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3763\\\/more-fun-with-string-properties\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3763\\\/more-fun-with-string-properties\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3763\\\/more-fun-with-string-properties\\\/\",\"name\":\"More Fun with String Properties &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3763\\\/more-fun-with-string-properties\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3763\\\/more-fun-with-string-properties\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2014\\\/03\\\/convert-clioutput-1-1024x633.png\",\"datePublished\":\"2014-03-27T19:41:21+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3763\\\/more-fun-with-string-properties\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3763\\\/more-fun-with-string-properties\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3763\\\/more-fun-with-string-properties\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2014\\\/03\\\/convert-clioutput-1.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2014\\\/03\\\/convert-clioutput-1.png\",\"width\":1150,\"height\":711},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3763\\\/more-fun-with-string-properties\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"CommandLine\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/commandline\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"More Fun with String Properties\"}]},{\"@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":"More Fun with String Properties &#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\/3763\/more-fun-with-string-properties\/","og_locale":"en_US","og_type":"article","og_title":"More Fun with String Properties &#8226; The Lonely Administrator","og_description":"The other day I posted an article about converting string properties that you might get from running a command line tool into a PowerShell named property. I was continuing to experiment with it. Here's some code on how I could use it. $raw = qprocess $properties = $raw[0] -split \"s{2,}\" | Convert-StringProperty $raw | select...","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3763\/more-fun-with-string-properties\/","og_site_name":"The Lonely Administrator","article_published_time":"2014-03-27T19:41:21+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/03\/convert-clioutput-1-1024x633.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":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3763\/more-fun-with-string-properties\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3763\/more-fun-with-string-properties\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"More Fun with String Properties","datePublished":"2014-03-27T19:41:21+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3763\/more-fun-with-string-properties\/"},"wordCount":574,"commentCount":5,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3763\/more-fun-with-string-properties\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/03\/convert-clioutput-1-1024x633.png","keywords":["PowerShell","Regular Expressions","Scripting"],"articleSection":["CommandLine","PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/3763\/more-fun-with-string-properties\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3763\/more-fun-with-string-properties\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3763\/more-fun-with-string-properties\/","name":"More Fun with String Properties &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3763\/more-fun-with-string-properties\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3763\/more-fun-with-string-properties\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/03\/convert-clioutput-1-1024x633.png","datePublished":"2014-03-27T19:41:21+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3763\/more-fun-with-string-properties\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/3763\/more-fun-with-string-properties\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3763\/more-fun-with-string-properties\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/03\/convert-clioutput-1.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/03\/convert-clioutput-1.png","width":1150,"height":711},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3763\/more-fun-with-string-properties\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"CommandLine","item":"https:\/\/jdhitsolutions.com\/blog\/category\/commandline\/"},{"@type":"ListItem","position":2,"name":"More Fun with String Properties"}]},{"@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":3757,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3757\/convert-a-string-to-a-powershell-property-name\/","url_meta":{"origin":3763,"position":0},"title":"Convert a String to a PowerShell Property Name","author":"Jeffery Hicks","date":"March 25, 2014","format":false,"excerpt":"Over the last few years I've written and presented a bit on the idea of turning command line tools into PowerShell tools. We have a lot of great CLI based tools that are still worth using. What I've done is come up with tools and techniques for turning their output\u2026","rel":"","context":"In &quot;CommandLine&quot;","block_context":{"text":"CommandLine","link":"https:\/\/jdhitsolutions.com\/blog\/category\/commandline\/"},"img":{"alt_text":"talkbubble","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/talkbubble.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1716,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1716\/convert-text-to-object\/","url_meta":{"origin":3763,"position":1},"title":"Convert Text to Object","author":"Jeffery Hicks","date":"October 25, 2011","format":false,"excerpt":"Today I have another tool in my new battle regarding turning command line tools into PowerShell tools. The bottom line is we want to have objects written to the pipeline. At the PowerShell Deep Dive in Frankfurt there was a suggestion about providing tools to help with the transformation from\u2026","rel":"","context":"In &quot;CommandLine&quot;","block_context":{"text":"CommandLine","link":"https:\/\/jdhitsolutions.com\/blog\/category\/commandline\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":7937,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7937\/creating-powershell-property-names\/","url_meta":{"origin":3763,"position":2},"title":"Creating PowerShell Property Names","author":"Jeffery Hicks","date":"December 8, 2020","format":false,"excerpt":"The last week or so I've been playing with a new PowerShell project from Dave Carroll for using Twitter from a PowerShell prompt. The module is called BluebirdPS and you can install it from the PowerShell Gallery. The module is very much still in its early stages but is functional\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\/2020\/12\/psobject-properites.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/12\/psobject-properites.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/12\/psobject-properites.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/12\/psobject-properites.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":5602,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/5602\/whos-driving-this-shell\/","url_meta":{"origin":3763,"position":3},"title":"Who&rsquo;s Driving this Shell?","author":"Jeffery Hicks","date":"August 8, 2017","format":false,"excerpt":"Microsoft has been busy with the next iteration of PowerShell. As you should already know, this version will run cross-platform. The executable, or engine, is naturally different than what you are used to with Windows PowerShell. As I was trying out the latest PowerShell beta, I needed to identify the\u2026","rel":"","context":"In &quot;PowerCLI&quot;","block_context":{"text":"PowerCLI","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powercli\/"},"img":{"alt_text":"2017-08-08_10-29-38","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2017\/08\/2017-08-08_10-29-38_thumb.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2017\/08\/2017-08-08_10-29-38_thumb.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2017\/08\/2017-08-08_10-29-38_thumb.png?resize=525%2C300 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2017\/08\/2017-08-08_10-29-38_thumb.png?resize=700%2C400 2x"},"classes":[]},{"id":3727,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/3727\/find-and-replace-text-with-powershell\/","url_meta":{"origin":3763,"position":4},"title":"Find and Replace Text with PowerShell","author":"Jeffery Hicks","date":"February 27, 2014","format":false,"excerpt":"I've just finished up a series of tweets with a follower who had a question about finding and replacing a bit of data in a text file. In his case it was a web.config file but it really could be any text file that you can view in PowerShell. In\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":"magnifying-glass","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/11\/magnifying-glass.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":6855,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell-7\/6855\/powershell-scripting-for-linux-is-still-about-the-objects\/","url_meta":{"origin":3763,"position":5},"title":"PowerShell Scripting for Linux is Still About the Objects","author":"Jeffery Hicks","date":"October 8, 2019","format":false,"excerpt":"I've been trying to increase my Linux skills, especially as I begin to write PowerShell scripts and tools that can work cross-platform. One very important concept I want to make sure you don't overlook is that even when scripting for non-Windows platforms, you must still be thinking about objects. The\u2026","rel":"","context":"In &quot;PowerShell 7&quot;","block_context":{"text":"PowerShell 7","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-7\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3763","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=3763"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3763\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=3763"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=3763"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=3763"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}