{"id":9074,"date":"2022-07-05T10:09:17","date_gmt":"2022-07-05T14:09:17","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=9074"},"modified":"2022-07-05T10:09:22","modified_gmt":"2022-07-05T14:09:22","slug":"the-value-of-objects","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9074\/the-value-of-objects\/","title":{"rendered":"The Value of Objects"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>This is a reprint of an article published earlier this year in my premium PowerShell newsletter, <a href=\"https:\/\/jeffhicks.substack.com\" target=\"_blank\" rel=\"noreferrer noopener\">Behind the PowerShell Pipeline.<\/a> This is a sample of what my subscribers get 6-8 times a month.<\/p><\/blockquote>\n\n\n\n<p>I expect I will write several articles about PowerShell and its relationship with objects. I know that this is the biggest hurdle for PowerShell beginners to overcome. But once they grasp that PowerShell is about working with objects in the pipeline, they recognize the value and begin finding it easier to write PowerShell code and use it interactively at a console prompt.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">In a Console A Long, Long Time Ago<\/h2>\n\n\n\n<p>Don't forget that I am approaching PowerShell from the role of an IT pro. Many of these people come to PowerShell with other automation and scripting skills. It might be old-fashioned batch files. It might be extensive experience with VBScript. That was my PowerShell journey. Like many of you, my initial PowerShell experiences were colored by my past. I kept trying to make PowerShell write text as I did with VBScript. Here's an old example.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"visual-basic\" class=\"language-visual-basic\">Dim objSet, wshell\nOn Error Resume Next\n\nSet wshell=CreateObject(\"Wscript.Shell\")\n\nIf wscript.arguments.count=0 Then\n strSrv=InputBox(\"What server do you want to check?  You must have admin rights on it.  Do NOT use \\\\ \" &amp; _\n \"before the servername.\",\"Disk Check\",\"SERVERNAME\")\n If strSrv=\"\" Then\n   wshell.popup \"Nothing entered or you cancelled\",4,\"Disk Check\",0+48\n   wscript.quit\n End If\nElse\n strSrv=Trim(wscript.arguments(0))\nEnd If\n\nstrQuery = \"Select * from win32_logicaldisk where drivetype=3\"\nSet objSet=GetObject(\"winmgmts:\\\\\" &amp; strSrv).ExecQuery(strQuery)\nif err.number&lt;>0 then\n wshell.popup \"Oops! Error connecting to \" &amp; UCase(strSrv) &amp; vbCrlf &amp; \"make sure you are using valid \" &amp; _\n \"credentials.\" &amp; vbCrlf &amp; \"Error: \" &amp; err.number &amp; \" - \" &amp; err.description,5,\"Disk Check Error\",0+48\n wscript.quit\nend if\n\nFor Each item In objSet\n   PerFree=FormatPercent(item.FreeSpace\/item.Size,2)\n   o=o &amp; item.DeviceID &amp; \"\\\" &amp; VBTAB\n   o=o &amp; FormatNumber(item.Size\/1048576,0) &amp; Vbtab &amp; FormatNumber(item.FreeSpace\/1048576,0) &amp; Vbtab &amp; PerFree &amp; Vbcrlf\nnext\nWScript.Echo \"Drive\" &amp; Vbtab &amp; \"Size (MB) Free (MB) %Free\" &amp; VbCrLf &amp; o\nset objSet=Nothing\nset wshell=Nothing\n\nwscript.quit<\/code><\/pre>\n\n\n\n<p>Don't panic. I'm not going to try and teach you VBScript. The script is getting disk information from WMI and displaying a summary. But to get the desired result, I spend a lot of time creating strings of text to display. In the <code>For Each item<\/code> section, I am building a string for each drive showing the size and free space. Each drive\u00a0 gets concatenated to the variable <code>o<\/code>. At the end of the script, I write the string of information to the screen.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"visual-basic\" class=\"language-visual-basic\">WScript.Echo \"Drive\" &amp; Vbtab &amp; \"Size (MB) Free (MB) %Free\" &amp; VbCrLf &amp; o<\/code><\/pre>\n\n\n\n<p>Here's what I end up with.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/vbs-wmidiskspace.png\"><img loading=\"lazy\" decoding=\"async\" width=\"636\" height=\"234\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/vbs-wmidiskspace.png\" alt=\"VBScript WMI output\" class=\"wp-image-9077\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/vbs-wmidiskspace.png 636w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/vbs-wmidiskspace-300x110.png 300w\" sizes=\"auto, (max-width: 636px) 100vw, 636px\" \/><\/a><\/figure>\n\n\n\n<p>Many people new to PowerShell are trying to force it to behave like this. They are used to a scripting language returning a string of text. This is especially true of people with a background in Linux bash scripting. Because Linux is a text-based operating system, its tools are based on the concept of parsing text. Someone new to PowerShell and still stuck in the text paradigm might write a PowerShell script like this.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$strSrv = Read-Host \"Enter a computername\"\n$strQuery = \"Select * from win32_logicaldisk where drivetype=3\"\n$objSet = Get-WmiObject -Query $strQuery -ComputerName $strSrv\nWrite-Host \"Drive`t Size (MB)       Free (MB)       %Free\"\nforeach ($item in $objSet) {\n$perFree = ($item.FreeSpace\/$item.size)*100\n$line = $item.DeviceID + \"\\   `t\" + $item.Size\/1048576 + \"  \" + $item.FreeSpace\/1048576 + \"  \" + $perFree\nWrite-Host $line\n}<\/code><\/pre>\n\n\n\n<p>Sadly, I have seen code like this in the real world. It will work. Sort of.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/vbs-as-ps.png\"><img loading=\"lazy\" decoding=\"async\" width=\"643\" height=\"166\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/vbs-as-ps.png\" alt=\"vbscript as powershell\" class=\"wp-image-9078\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/vbs-as-ps.png 643w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/vbs-as-ps-300x77.png 300w\" sizes=\"auto, (max-width: 643px) 100vw, 643px\" \/><\/a><\/figure>\n\n\n\n<p>But this is a lot of work. One reason people get hung up on text is that running a command in PowerShell almost always produces easy-to-read text output. Think of the result you get from<code> Get-Service<\/code> and <code>Get-Process.<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Objects Are Easy<\/h2>\n\n\n\n<p>The idea of an object shouldn't be that difficult. We deal with objects in the real world every day. The challenge is getting our heads wrapped around the concept of virtual objects. If you take the time to look at PowerShell, you'll see it is trying to help you. The command names imply objects. <code>Get-Service<\/code> is going to get service objects. Here's a situation where using the full cmdlet name instead of the <em>gsv<\/em> alias can help a beginner. You don't want to learn PowerShell thinking, \"When I run the gsv command, I get a list of services.\" You want to be thinking, \"When I run the Get-Service command, I am getting a collection of service objects that I can pass on to another command.\"<\/p>\n\n\n\n<p>Let's revisit the WMI code. The code says, \"Get me a WMI object that is a Win32_Logicialdisk that meets specific criteria on the specified remote computer.\" Once those objects have been returned, the code tells PowerShell what object properties to display. The results are displayed, and PowerShell automatically handles all of the formatting.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$computername  = Read-Host \"Enter a computername\"\n$Query = \"Select * from win32_logicaldisk where drivetype=3\"\nGet-WmiObject -Query $Query -ComputerName $computername | \nSelect-Object -property DeviceID,Size,Freespace,\n@{Name=\"PercentFree\";Expression = {$_.freespace\/$_.size}}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/formatted-results.png\"><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"165\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/formatted-results.png\" alt=\"formatted results in PowerShell\" class=\"wp-image-9080\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/formatted-results.png 624w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/formatted-results-300x79.png 300w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/a><\/figure>\n\n\n\n<p>One of the best features of PowerShell is that you can also define new object properties. The WMI win32_logicaldisk object doesn't have a PercentFree property. But <code>Select-Object<\/code> can do that for me with the custom hashtable. <\/p>\n\n\n\n<p>Once you start thinking about objects and not parsing text, you'll realize there is an entire world of possibilities. I tell beginning PowerShell scripters to say aloud what they want PowerShell to do.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><em>Get all fixed logical disks from a remote computer. Select the computer name, drive letter, size in GB, free disk\u00a0space, and percent free space and export to a CSV file.<\/em><\/p><\/blockquote>\n\n\n\n<p>Once you articulate what you want, you can find the PowerShell commands and parameters to make it happen.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Get-CimInstance -ClassName Win32_LogicalDisk -Filter \"DriveType=3\" -ComputerName $computername |Select-Object -property DeviceID,@{Name=\"SizeGB\";Expression = {$_.size\/1GB -as [int32]}},Freespace,@{Name=\"PercentFree\";Expression = {($_.freespace\/$_.size)*100}},SystemName |Export-CSV c:\\work\\diskinfo.csv -Append<\/code><\/pre>\n\n\n\n<p>The biggest hurdle for beginners is discovering object properties with <code>Get-Member<\/code> and the tricks to format values, such as using the 1GB shortcut and the <code>-As<\/code> operator. I have found that the people who can visualize the concept of objects in the pipeline adopt PowerShell quicker and with less pain.<\/p>\n\n\n\n<p>That's not to say we still don't need to mess with text or values. The percent free value I defined above is a\u00a0 good example. You might be inclined to use the <code>-f<\/code> operator.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">@{Name=\"PercentFree\";Expression = {\"{0:p2}\" -f ($_.freespace\/$_.size)}}<\/code><\/pre>\n\n\n\n<p>It sure looks nice.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/formatted-percent.png\"><img loading=\"lazy\" decoding=\"async\" width=\"372\" height=\"445\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/formatted-percent.png\" alt=\"formatted percentages\" class=\"wp-image-9081\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/formatted-percent.png 372w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/formatted-percent-251x300.png 251w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/formatted-percent-300x359.png 300w\" sizes=\"auto, (max-width: 372px) 100vw, 372px\" \/><\/a><\/figure>\n\n\n\n<p>If all I want to do is look at this result, I might be ok. But even here, we're back to text. If I pipe this output to <code>Get-Member<\/code> I'll see that the PercentFree property is a <code>System.String<\/code>. The problem arises when I want to do something with the value, such as sorting. The value will sort as a string, not a number, and I might not get the expected results.<\/p>\n\n\n\n<p>I find a better approach is to treat the value as a <code>[System.Double]<\/code> object using the [math] class to\u00a0round the value to 2 decimal places.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">@{Name=\"PercentFree\";Expression = {[math]::round(($_.freespace\/$_.size)*100,2)}}<\/code><\/pre>\n\n\n\n<p>With this, I get the formatted percentage I want and a value I can use.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/sorted-percent.png\"><img loading=\"lazy\" decoding=\"async\" width=\"578\" height=\"296\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/sorted-percent.png\" alt=\"\" class=\"wp-image-9082\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/sorted-percent.png 578w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/sorted-percent-300x154.png 300w\" sizes=\"auto, (max-width: 578px) 100vw, 578px\" \/><\/a><\/figure>\n\n\n\n<p>I hope you can see the value here.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Functions Write Objects<\/h2>\n\n\n\n<p>The last part of the story I want to discuss briefly revolves around PowerShell functions. I have very strong opinions on how to write a PowerShell function properly and how it should behave. This is often at odds with people who come to PowerShell with a developer background or maybe used to writing VBScript subroutines.<\/p>\n\n\n\n<p>While I recognize there are exceptions, a PowerShell function should write a series of objects, or maybe a single object, to the pipeline. It is not returning anything that looks like a string. Technically, there is nothing wrong with this simple PowerShell function.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Function Get-PercentFree {\n    Param($Drive = \"C:\", $Computername = $env:COMPUTERNAME)\n\n    $d = Get-CimInstance -ClassName Win32_LogicalDisk -Filter \"DeviceID='$Drive'\" -ComputerName $computername\n    $p = [math]::round(($d.freespace \/ $d.size) * 100, 2)\n    return $p\n}<\/code><\/pre>\n\n\n\n<p>But it is of limited value. All I'm going to get is a result like 40.96. I would have written this type of code as a VBScript subroutine. But we're talking about PowerShell. I want an object in the pipeline.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Function Get-LogicalDisk {\n    [cmdletbinding()]\n    Param($Computername = $env:COMPUTERNAME)\n\n    $disks = Get-CimInstance -ClassName Win32_LogicalDisk -Filter \"DriveType=3\" -ComputerName $computername\n    $disks | Select-Object @{Name = \"Computername\"; Expression = { $_.SystemName } },\n    DeviceID, Size, FreeSpace, @{Name = \"PercentFree\"; Expression = { [math]::round(($_.freespace \/ $_.size) * 100, 2) } },\n    @{Name = \"Audit\"; Expression = { Get-Date } }\n}<\/code><\/pre>\n\n\n\n<p>The function is written to make a point, not necessarily something ready for production. Running the function gives this kind of output.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/get-logicaldisk.png\"><img loading=\"lazy\" decoding=\"async\" width=\"584\" height=\"420\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/get-logicaldisk.png\" alt=\"get logical disk objects\" class=\"wp-image-9083\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/get-logicaldisk.png 584w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/get-logicaldisk-300x216.png 300w\" sizes=\"auto, (max-width: 584px) 100vw, 584px\" \/><\/a><\/figure>\n\n\n\n<p>If all I need is percent free, that is easy enough to retrieve.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/getting-drive-usage.png\"><img loading=\"lazy\" decoding=\"async\" width=\"621\" height=\"366\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/getting-drive-usage.png\" alt=\"getting drive usage with PowerShell\" class=\"wp-image-9084\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/getting-drive-usage.png 621w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/getting-drive-usage-300x177.png 300w\" sizes=\"auto, (max-width: 621px) 100vw, 621px\" \/><\/a><\/figure>\n\n\n\n<p>The function is flexible and re-usable because it writes a rich object to the pipeline. <\/p>\n\n\n\n<p>If you noticed in the function, I also did not format the size and free space values. I left them in bytes. Getting or creating an object in PowerShell is separate from how it is formatted or presented. But that's a topic for another day.<\/p>\n\n\n\n<p>If I need strings, say for a log file, I can still create them from objects.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$data = \"prospero\",\"thinkx1-jh\",\"dom1\",\"srv2\" | \nForeach-Object { Get-LogicalDisk -Computername $_ }\nforeach ($item in $data) {\n $line = \"[{0:d}] Drive {1} on {2} is {3}% free\" -f $item.Audit,$item.DeviceID,$item.computername,$item.percentfree\n $line\n #$line | Out-File log.txt -append\n}<\/code><\/pre>\n\n\n\n<p>Note that because the Audit property is a datetime object, I can format it using the <code>d<\/code> qualifier.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/text-from-objects.png\"><img loading=\"lazy\" decoding=\"async\" width=\"584\" height=\"186\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/text-from-objects.png\" alt=\"text from objects\" class=\"wp-image-9086\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/text-from-objects.png 584w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/text-from-objects-300x96.png 300w\" sizes=\"auto, (max-width: 584px) 100vw, 584px\" \/><\/a><\/figure>\n\n\n\n<p>Trying to accomplish this with a text-based paradigm is much more complicated and frustrating. <\/p>\n\n\n\n<p>The more you think about the object you can get from PowerShell and how you can use it, the more you can accomplish, and most likely with better PowerShell code.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a reprint of an article published earlier this year in my premium PowerShell newsletter, Behind the PowerShell Pipeline. This is a sample of what my subscribers get 6-8 times a month. I expect I will write several articles about PowerShell and its relationship with objects. I know that this is the biggest hurdle&#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: Recognizing the value of objects in #PowerShell","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":[4,8],"tags":[224,534,540,662],"class_list":["post-9074","post","type-post","status-publish","format-standard","hentry","category-powershell","category-scripting","tag-function","tag-powershell","tag-scripting","tag-substack"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>The Value of Objects &#8226; The Lonely Administrator<\/title>\n<meta name=\"description\" content=\"This is a reprint of an article written earlier this year for my premium PowerShell newsletter. Here I discuss the value of thinking &quot;objects&quot;.\" \/>\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\/9074\/the-value-of-objects\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The Value of Objects &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"This is a reprint of an article written earlier this year for my premium PowerShell newsletter. Here I discuss the value of thinking &quot;objects&quot;.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/9074\/the-value-of-objects\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2022-07-05T14:09:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-05T14:09:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/vbs-wmidiskspace.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=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9074\\\/the-value-of-objects\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9074\\\/the-value-of-objects\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"The Value of Objects\",\"datePublished\":\"2022-07-05T14:09:17+00:00\",\"dateModified\":\"2022-07-05T14:09:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9074\\\/the-value-of-objects\\\/\"},\"wordCount\":1225,\"commentCount\":4,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9074\\\/the-value-of-objects\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/vbs-wmidiskspace.png\",\"keywords\":[\"Function\",\"PowerShell\",\"Scripting\",\"substack\"],\"articleSection\":[\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9074\\\/the-value-of-objects\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9074\\\/the-value-of-objects\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9074\\\/the-value-of-objects\\\/\",\"name\":\"The Value of Objects &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9074\\\/the-value-of-objects\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9074\\\/the-value-of-objects\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/vbs-wmidiskspace.png\",\"datePublished\":\"2022-07-05T14:09:17+00:00\",\"dateModified\":\"2022-07-05T14:09:22+00:00\",\"description\":\"This is a reprint of an article written earlier this year for my premium PowerShell newsletter. Here I discuss the value of thinking \\\"objects\\\".\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9074\\\/the-value-of-objects\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9074\\\/the-value-of-objects\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9074\\\/the-value-of-objects\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/vbs-wmidiskspace.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/vbs-wmidiskspace.png\",\"width\":636,\"height\":234},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/9074\\\/the-value-of-objects\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"The Value of Objects\"}]},{\"@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":"The Value of Objects &#8226; The Lonely Administrator","description":"This is a reprint of an article written earlier this year for my premium PowerShell newsletter. Here I discuss the value of thinking \"objects\".","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\/9074\/the-value-of-objects\/","og_locale":"en_US","og_type":"article","og_title":"The Value of Objects &#8226; The Lonely Administrator","og_description":"This is a reprint of an article written earlier this year for my premium PowerShell newsletter. Here I discuss the value of thinking \"objects\".","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9074\/the-value-of-objects\/","og_site_name":"The Lonely Administrator","article_published_time":"2022-07-05T14:09:17+00:00","article_modified_time":"2022-07-05T14:09:22+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/vbs-wmidiskspace.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":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9074\/the-value-of-objects\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9074\/the-value-of-objects\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"The Value of Objects","datePublished":"2022-07-05T14:09:17+00:00","dateModified":"2022-07-05T14:09:22+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9074\/the-value-of-objects\/"},"wordCount":1225,"commentCount":4,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9074\/the-value-of-objects\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/vbs-wmidiskspace.png","keywords":["Function","PowerShell","Scripting","substack"],"articleSection":["PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/9074\/the-value-of-objects\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9074\/the-value-of-objects\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9074\/the-value-of-objects\/","name":"The Value of Objects &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9074\/the-value-of-objects\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9074\/the-value-of-objects\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/vbs-wmidiskspace.png","datePublished":"2022-07-05T14:09:17+00:00","dateModified":"2022-07-05T14:09:22+00:00","description":"This is a reprint of an article written earlier this year for my premium PowerShell newsletter. Here I discuss the value of thinking \"objects\".","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9074\/the-value-of-objects\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/9074\/the-value-of-objects\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9074\/the-value-of-objects\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/vbs-wmidiskspace.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/07\/vbs-wmidiskspace.png","width":636,"height":234},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9074\/the-value-of-objects\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"The Value of Objects"}]},{"@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":4707,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4707\/a-better-powershell-more\/","url_meta":{"origin":9074,"position":0},"title":"A Better PowerShell More","author":"Jeffery Hicks","date":"December 23, 2015","format":false,"excerpt":"In PowerShell, when I have a lot of output, I can use the legacy more.com command to page the results to the screen. Get-Process | more There's not anything inherently wrong with this approach. Although one drawback is that it doesn't work in the PowerShell ISE. For that reason alone\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"More PowerShell Output","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2015\/12\/image_thumb-6.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2015\/12\/image_thumb-6.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2015\/12\/image_thumb-6.png?resize=525%2C300 1.5x"},"classes":[]},{"id":840,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/840\/pipelines-consoles-and-hosts\/","url_meta":{"origin":9074,"position":1},"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":2044,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2044\/maximizing-the-powershell-console-title-bar\/","url_meta":{"origin":9074,"position":2},"title":"Maximizing the PowerShell Console Title Bar","author":"Jeffery Hicks","date":"January 31, 2012","format":false,"excerpt":"A few days ago Boe Prox posted some very nifty PowerShell modules for using the title bar as a ticker for RSS feeds like the weather. I thought this was an awesome idea and an easy way to take advantage of what would otherwise be unused screen space. I was\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":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/01\/console-title-sysstat-300x85.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":9074,"position":3},"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":[]},{"id":449,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/449\/drive-report-console-chart\/","url_meta":{"origin":9074,"position":4},"title":"Drive Report Console Chart","author":"Jeffery Hicks","date":"October 15, 2009","format":false,"excerpt":"In thinking about some of my recent posts, I realize I should make clear that these scripts and functions are not necessarily good PowerShell examples. They don\u2019t take advantage of objects and the pipeline. They are single purpose and one-dimensional. Not that there\u2019s anything wrong with that. My recent examples,\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"drivereport screenshot","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/10\/drivereport_thumb.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":3000,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3000\/why-doesnt-my-pipeline-work\/","url_meta":{"origin":9074,"position":5},"title":"Why Doesn&#8217;t My Pipeline Work?","author":"Jeffery Hicks","date":"May 7, 2013","format":false,"excerpt":"I saw a little discussion thread on Twitter this morning which I felt needed a little more room to explain. Plus since we're in ScriptingGames season beginners might like a few pointers. I always talk about PowerShell, objects and the pipeline. But sometimes what looks like a pipelined expression in\u2026","rel":"","context":"In &quot;Best Practices&quot;","block_context":{"text":"Best Practices","link":"https:\/\/jdhitsolutions.com\/blog\/category\/best-practices\/"},"img":{"alt_text":"talkbubble","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/talkbubble-150x150.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/9074","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=9074"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/9074\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=9074"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=9074"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=9074"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}