{"id":685,"date":"2010-07-01T11:40:27","date_gmt":"2010-07-01T16:40:27","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/2010\/07\/objects-are-the-answer\/"},"modified":"2010-07-01T12:11:55","modified_gmt":"2010-07-01T17:11:55","slug":"objects-are-the-answer","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/scripting\/685\/objects-are-the-answer\/","title":{"rendered":"Objects are the answer"},"content":{"rendered":"<p>As I usually do, I was helping out in the forums at <a title=\"Visit ScriptingAnswers.com\" href=\"http:\/\/www.scriptinganswers.com\" target=\"_blank\">ScriptingAnswers.com<\/a>. A member had several variables that he wanted to show as a group. As is almost always the case, the answer in PowerShell is object. I talk about this all the time in classes, conferences and online chitchat. Let me offer up a script that demonstrates how objects are the answer.<\/p>\n<p>My business need was to report on files found in a given folder or path. I wanted to get a breakdown of file types showing me the number of each type, their total size and their percentage of all files by count and size.<\/p>\n<pre class=\"PowerShellColorizedScript\"><span style=\"color: #006400;\">#requires -version 2.0<\/span>            \r\n\r\n<span style=\"color: #00008b;\">Param<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #008080;\">[string]<\/span><span style=\"color: #ff4500;\">$path<\/span><span style=\"color: #a9a9a9;\">=<\/span><span style=\"color: #8b0000;\">\"$env:userprofile\\documents\"<\/span><span style=\"color: #000000;\">)<\/span>            \r\n\r\n<span style=\"color: #00008b;\">if<\/span> <span style=\"color: #000000;\">(<\/span><span style=\"color: #0000ff;\">Test-Path<\/span> <span style=\"color: #000080;\">-path<\/span> <span style=\"color: #ff4500;\">$path<\/span><span style=\"color: #000000;\">)<\/span> <span style=\"color: #000000;\">{<\/span>\r\n    <span style=\"color: #0000ff;\">write-host<\/span> <span style=\"color: #8b0000;\">\"Collecting file information for $path\"<\/span> `<\/pre>\n<pre class=\"PowerShellColorizedScript\">   <span style=\"color: #000080;\">-ForegroundColor<\/span> <span style=\"color: #8a2be2;\">Green<\/span>            \r\n\r\n    <span style=\"color: #ff4500;\">$files<\/span><span style=\"color: #a9a9a9;\">=<\/span><span style=\"color: #0000ff;\">dir<\/span>  <span style=\"color: #ff4500;\">$path<\/span> <span style=\"color: #000080;\">-recurse<\/span> <span style=\"color: #000080;\">-errorAction<\/span> <span style=\"color: #8b0000;\">\"SilentlyContinue\"<\/span> <span style=\"color: #a9a9a9;\">|<\/span><\/pre>\n<pre class=\"PowerShellColorizedScript\">     <span style=\"color: #0000ff;\">where<\/span> <span style=\"color: #000000;\">{<\/span><span style=\"color: #a9a9a9;\">-not<\/span> <span style=\"color: #ff4500;\">$_<\/span><span style=\"color: #a9a9a9;\">.<\/span><span style=\"color: #000000;\">PSIsContainer<\/span><span style=\"color: #000000;\">}<\/span>\r\n    <span style=\"color: #ff4500;\">$stats<\/span><span style=\"color: #a9a9a9;\">=<\/span><span style=\"color: #ff4500;\">$files<\/span> <span style=\"color: #a9a9a9;\">|<\/span> <span style=\"color: #0000ff;\">Measure-Object<\/span> <span style=\"color: #000080;\">-Property<\/span> <span style=\"color: #8a2be2;\">Length<\/span> <span style=\"color: #000080;\">-sum<\/span>\r\n    <span style=\"color: #ff4500;\">$grouped<\/span><span style=\"color: #a9a9a9;\">=<\/span><span style=\"color: #ff4500;\">$files<\/span> <span style=\"color: #a9a9a9;\">|<\/span> <span style=\"color: #0000ff;\">group<\/span> <span style=\"color: #000080;\">-property<\/span> <span style=\"color: #8a2be2;\">Extension<\/span>            \r\n\r\n    <span style=\"color: #00008b;\">foreach<\/span> <span style=\"color: #000000;\">(<\/span><span style=\"color: #ff4500;\">$group<\/span> <span style=\"color: #00008b;\">in<\/span> <span style=\"color: #ff4500;\">$grouped<\/span><span style=\"color: #000000;\">)<\/span> <span style=\"color: #000000;\">{<\/span>\r\n        <span style=\"color: #006400;\">#measure the total size of each file type<\/span>\r\n        <span style=\"color: #ff4500;\">$measure<\/span><span style=\"color: #a9a9a9;\">=<\/span><span style=\"color: #ff4500;\">$group<\/span><span style=\"color: #a9a9a9;\">.<\/span><span style=\"color: #000000;\">group<\/span> <span style=\"color: #a9a9a9;\">|<\/span> <span style=\"color: #0000ff;\">measure-object<\/span> <span style=\"color: #000080;\">-Property<\/span> <span style=\"color: #8a2be2;\">length<\/span> <span style=\"color: #000080;\">-sum<\/span>            \r\n\r\n        <span style=\"color: #006400;\">#calculate % of total size<\/span>\r\n        <span style=\"color: #ff4500;\">$perSize<\/span><span style=\"color: #a9a9a9;\">=<\/span><span style=\"color: #8b0000;\">\"{0:P4}\"<\/span> <span style=\"color: #a9a9a9;\">-f<\/span> <span style=\"color: #000000;\">(<\/span><span style=\"color: #ff4500;\">$measure<\/span><span style=\"color: #a9a9a9;\">.<\/span><span style=\"color: #000000;\">sum<\/span><span style=\"color: #a9a9a9;\">\/<\/span><span style=\"color: #ff4500;\">$stats<\/span><span style=\"color: #a9a9a9;\">.<\/span><span style=\"color: #000000;\">sum<\/span><span style=\"color: #000000;\">)<\/span>            \r\n\r\n        <span style=\"color: #006400;\">#calculate % of total number<\/span>\r\n        <span style=\"color: #ff4500;\">$perTotal<\/span><span style=\"color: #a9a9a9;\">=<\/span><span style=\"color: #8b0000;\">\"{0:P4}\"<\/span> <span style=\"color: #a9a9a9;\">-f<\/span> <span style=\"color: #000000;\">(<\/span><span style=\"color: #ff4500;\">$measure<\/span><span style=\"color: #a9a9a9;\">.<\/span><span style=\"color: #000000;\">count<\/span><span style=\"color: #a9a9a9;\">\/<\/span><span style=\"color: #ff4500;\">$stats<\/span><span style=\"color: #a9a9a9;\">.<\/span><span style=\"color: #000000;\">count<\/span><span style=\"color: #000000;\">)<\/span>            \r\n\r\n        <span style=\"color: #006400;\">#write a custom object to the pipeline<\/span>\r\n        <span style=\"color: #0000ff;\">new-object<\/span> <span style=\"color: #8a2be2;\">psobject<\/span> <span style=\"color: #000080;\">-Property<\/span> <span style=\"color: #000000;\">@{<\/span>\r\n            <span style=\"color: #000000;\">Extension<\/span><span style=\"color: #a9a9a9;\">=<\/span><span style=\"color: #ff4500;\">$group<\/span><span style=\"color: #a9a9a9;\">.<\/span><span style=\"color: #000000;\">name<\/span>\r\n            <span style=\"color: #000000;\">Total<\/span><span style=\"color: #a9a9a9;\">=<\/span><span style=\"color: #ff4500;\">$group<\/span><span style=\"color: #a9a9a9;\">.<\/span><span style=\"color: #000000;\">count<\/span>\r\n            <span style=\"color: #000000;\">TotalSizeMB<\/span><span style=\"color: #a9a9a9;\">=<\/span><span style=\"color: #008080;\">[Math]<\/span><span style=\"color: #a9a9a9;\">::<\/span><span style=\"color: #000000;\">Round<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #ff4500;\">$measure<\/span><span style=\"color: #a9a9a9;\">.<\/span><span style=\"color: #000000;\">sum<\/span><span style=\"color: #a9a9a9;\">\/<\/span><span style=\"color: #800080;\">1mb<\/span><span style=\"color: #a9a9a9;\">,<\/span><span style=\"color: #800080;\">2<\/span><span style=\"color: #000000;\">)<\/span>\r\n            <span style=\"color: #000000;\">PercentTotal<\/span><span style=\"color: #a9a9a9;\">=<\/span><span style=\"color: #ff4500;\">$perTotal<\/span>\r\n            <span style=\"color: #000000;\">PercentSize<\/span><span style=\"color: #a9a9a9;\">=<\/span><span style=\"color: #ff4500;\">$perSize<\/span>\r\n            <span style=\"color: #000000;\">Files<\/span><span style=\"color: #a9a9a9;\">=<\/span><span style=\"color: #ff4500;\">$group<\/span><span style=\"color: #a9a9a9;\">.<\/span><span style=\"color: #000000;\">group<\/span>\r\n        <span style=\"color: #000000;\">}<\/span>\r\n    <span style=\"color: #000000;\">}<\/span> <span style=\"color: #006400;\">#foreach<\/span>\r\n<span style=\"color: #000000;\">}<\/span> <span style=\"color: #006400;\">#if test-path<\/span>\r\n<span style=\"color: #00008b;\">else<\/span> <span style=\"color: #000000;\">{<\/span>\r\n    <span style=\"color: #0000ff;\">Write-Warning<\/span> <span style=\"color: #8b0000;\">\"Failed to find $path\"<\/span>\r\n<span style=\"color: #000000;\">}<\/span><\/pre>\n<p>The script takes a path as a parameter but defaults to your documents folder. Get-Childitem retrieves all files. I\u2019m setting the \u2013errorAction parameter to silentlycontinue to avoid the annoying error messages you get when trying to read protected system folders. The collection of files are then grouped by extension. Each group is then analyzed.<\/p>\n<p>At this point I have a number of pieces of information to display. In a VBScript I would have most like written some message to the screen for each file type. Technically I could do the same thing here but why? Using <a title=\"get online help for this cmdlet\" href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=113355\" target=\"_blank\">New-Object<\/a> I create a new object with properties for all my data. The objects written to the pipeline can be manipulated just like any other object. Let me check my C: drive.<\/p>\n<p><span style=\"font-family: Lucida Console; color: #0000ff; font-size: x-small;\">PS C:\\&gt; $c=c:\\scripts\\filestats.ps1 \u201cc:\\\u201d<\/span><\/p>\n<p>Hmmm\u2026how many different file types are on my computer?<\/p>\n<p><span style=\"font-family: Lucida Console; color: #0000ff; font-size: x-small;\">PS C:\\&gt; $c.count<br \/>\n1897<\/span><\/p>\n<p>Which file types are taking the most space?<\/p>\n<p><span style=\"font-family: Lucida Console; color: #0000ff; font-size: x-small;\">PS C:\\&gt; $c | sort totalsizeMB -desc | select -first 10 -property * -ExcludeProperty Files | format-table -auto <\/span><\/p>\n<p><span style=\"font-family: Lucida Console; color: #0000ff; font-size: x-small;\">TotalSizeMB PercentTotal Total Extension PercentSize<\/span><\/p>\n<p>----------- ------------ ----- --------- -----------<\/p>\n<p><span style=\"font-family: Lucida Console; color: #0000ff; font-size: x-small;\"> 115692.94 0.0637 %\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 90 .vmdk\u00a0\u00a0\u00a0\u00a0 57.8050 %<\/span><\/p>\n<p><span style=\"font-family: Lucida Console; color: #0000ff; font-size: x-small;\"> 19559.24 0.0219 %\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 31 .iso\u00a0\u00a0\u00a0\u00a0\u00a0 9.7726 %<br \/>\n14375.12 0.0014 %\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2 .vdi\u00a0\u00a0\u00a0\u00a0\u00a0 7.1824 %<\/span><span style=\"font-family: Lucida Console; color: #0000ff; font-size: x-small;\"><br \/>\n12440.64 14.8798 %\u00a0\u00a0\u00a0 21018 .dll\u00a0\u00a0\u00a0\u00a0\u00a0 6.2159 %<br \/>\n6972.15 2.4778 %\u00a0\u00a0\u00a0\u00a0\u00a0 3500 .exe\u00a0\u00a0\u00a0\u00a0\u00a0 3.4836 %<br \/>\n6190.48 0.0064 %\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 9 .wim\u00a0\u00a0\u00a0\u00a0\u00a0 3.0930 %<\/span><span style=\"font-family: Lucida Console; color: #0000ff; font-size: x-small;\"><br \/>\n2884.98 0.1373 %\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 194 .CAB\u00a0\u00a0\u00a0\u00a0\u00a0 1.4415 %<\/span><span style=\"font-family: Lucida Console; color: #0000ff; font-size: x-small;\"> <\/span><span style=\"font-family: Lucida Console; color: #0000ff; font-size: x-small;\"><br \/>\n2672.56 0.0021 %\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 3 .m4v\u00a0\u00a0\u00a0\u00a0\u00a0 1.3353 %<\/span><span style=\"font-family: Lucida Console; color: #0000ff; font-size: x-small;\"><br \/>\n1424.91 0.0042 %\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 6 .sav\u00a0\u00a0\u00a0\u00a0\u00a0 0.7119 %<br \/>\n1202.12 0.0092 %\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 13 .mp4\u00a0\u00a0\u00a0\u00a0\u00a0 0.6006 %<\/span><\/p>\n<p>My custom object even includes a property, files, which itself is a collection of objects. For example, what are the .vdi files?<\/p>\n<p><span style=\"font-family: Lucida Console; color: #0000ff; font-size: x-small;\">PS C:\\&gt; $c | where {$_.extension -eq \".vdi\"} | select -ExpandProperty Files<\/span><\/p>\n<p>Directory: C:\\VirtualBox\\Exchange<\/p>\n<p><span style=\"font-family: Lucida Console; color: #0000ff; font-size: x-small;\">Mode\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 LastWriteTime\u00a0\u00a0\u00a0\u00a0 Length Name<\/span><br \/>\n----\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0 \u00a0\u00a0 -------------\u00a0\u00a0\u00a0\u00a0 ------ ----<br \/>\n<span style=\"font-family: Lucida Console; color: #0000ff; font-size: x-small;\">-a---\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 6\/29\/2010\u00a0\u00a0 1:58 PM 1507336243 ExchangeHDD.vdi <\/span><\/p>\n<p><span style=\"font-family: Lucida Console; color: #0000ff; font-size: x-small;\"> <\/span><\/p>\n<p><span style=\"font-family: Lucida Console; color: #0000ff; font-size: x-small;\"> Directory: C:\\VirtualBox\\R2 <\/span><\/p>\n<p><span style=\"font-family: Lucida Console; color: #0000ff; font-size: x-small;\">Mode\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 LastWriteTime\u00a0\u00a0\u00a0\u00a0 Length Name<\/span><br \/>\n----\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0 \u00a0\u00a0 -------------\u00a0\u00a0\u00a0\u00a0 ------ ----<span style=\"font-family: Lucida Console; color: #0000ff; font-size: x-small;\"><br \/>\n-a---\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 6\/21\/2010\u00a0\u00a0 9:34 PM\u00a0\u00a0\u00a0\u00a0\u00a0 41472 ExchangeStore.vdi<\/span><\/p>\n<p>The bottom line is that having objects offers tremendous possibilities. So the next time you\u2019re working on a PowerShell problem, know that objects are the answer.<\/p>\n<p>My script was intended as a demonstration but if you\u2019d like a copy<\/p>\n<div id=\"scid:F60BB8FA-6F02-4999-8F5E-9DD4E92C4DA7:595fa751-0bab-47b7-8629-c0b826fa7acc\" class=\"wlWriterEditableSmartContent\" style=\"margin: 0px; display: inline; float: none; padding: 0px;\">\n<div><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/07\/FileStats.txt\" target=\"_blank\">download it here.<\/a><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>As I usually do, I was helping out in the forums at ScriptingAnswers.com. A member had several variables that he wanted to show as a group. As is almost always the case, the answer in PowerShell is object. I talk about this all the time in classes, conferences and online chitchat. Let me offer up&#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":"","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":[97,190,144,534,540],"class_list":["post-685","post","type-post","status-publish","format-standard","hentry","category-powershell-v2-0","category-scripting","tag-filesystem","tag-new-object","tag-objects","tag-powershell","tag-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Objects are the answer &#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\/685\/objects-are-the-answer\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Objects are the answer &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"As I usually do, I was helping out in the forums at ScriptingAnswers.com. A member had several variables that he wanted to show as a group. As is almost always the case, the answer in PowerShell is object. I talk about this all the time in classes, conferences and online chitchat. Let me offer up...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/scripting\/685\/objects-are-the-answer\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2010-07-01T16:40:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2010-07-01T17:11:55+00:00\" \/>\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\\\/685\\\/objects-are-the-answer\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/685\\\/objects-are-the-answer\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Objects are the answer\",\"datePublished\":\"2010-07-01T16:40:27+00:00\",\"dateModified\":\"2010-07-01T17:11:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/685\\\/objects-are-the-answer\\\/\"},\"wordCount\":418,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"keywords\":[\"FileSystem\",\"new-object\",\"objects\",\"PowerShell\",\"Scripting\"],\"articleSection\":[\"PowerShell v2.0\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/685\\\/objects-are-the-answer\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/685\\\/objects-are-the-answer\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/685\\\/objects-are-the-answer\\\/\",\"name\":\"Objects are the answer &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"datePublished\":\"2010-07-01T16:40:27+00:00\",\"dateModified\":\"2010-07-01T17:11:55+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/685\\\/objects-are-the-answer\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/685\\\/objects-are-the-answer\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/685\\\/objects-are-the-answer\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell v2.0\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell-v2-0\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Objects are the answer\"}]},{\"@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":"Objects are the answer &#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\/685\/objects-are-the-answer\/","og_locale":"en_US","og_type":"article","og_title":"Objects are the answer &#8226; The Lonely Administrator","og_description":"As I usually do, I was helping out in the forums at ScriptingAnswers.com. A member had several variables that he wanted to show as a group. As is almost always the case, the answer in PowerShell is object. I talk about this all the time in classes, conferences and online chitchat. Let me offer up...","og_url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/685\/objects-are-the-answer\/","og_site_name":"The Lonely Administrator","article_published_time":"2010-07-01T16:40:27+00:00","article_modified_time":"2010-07-01T17:11:55+00:00","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\/685\/objects-are-the-answer\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/685\/objects-are-the-answer\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Objects are the answer","datePublished":"2010-07-01T16:40:27+00:00","dateModified":"2010-07-01T17:11:55+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/685\/objects-are-the-answer\/"},"wordCount":418,"commentCount":0,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"keywords":["FileSystem","new-object","objects","PowerShell","Scripting"],"articleSection":["PowerShell v2.0","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/685\/objects-are-the-answer\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/685\/objects-are-the-answer\/","url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/685\/objects-are-the-answer\/","name":"Objects are the answer &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"datePublished":"2010-07-01T16:40:27+00:00","dateModified":"2010-07-01T17:11:55+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/685\/objects-are-the-answer\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/685\/objects-are-the-answer\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/685\/objects-are-the-answer\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell v2.0","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-v2-0\/"},{"@type":"ListItem","position":2,"name":"Objects are the answer"}]},{"@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":8409,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8409\/custom-csv-import-with-powershell\/","url_meta":{"origin":685,"position":0},"title":"Custom CSV Import with PowerShell","author":"Jeffery Hicks","date":"May 18, 2021","format":false,"excerpt":"I am always looking for opportunities to use PowerShell in a way that adds value to my work. And hopefully yours. This is one of the reasons it is worth the time and effort to learn PowerShell. It can be used in so many ways beyond the out-of-the-box commands. Once\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/importcsv-customtype.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/importcsv-customtype.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/importcsv-customtype.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/importcsv-customtype.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":4707,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4707\/a-better-powershell-more\/","url_meta":{"origin":685,"position":1},"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":6478,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6478\/powershell-scripting-getting-git-size-retooled\/","url_meta":{"origin":685,"position":2},"title":"Getting Git Size with PowerShell Retooled","author":"Jeffery Hicks","date":"January 30, 2019","format":false,"excerpt":"A few days ago I wrote about my experiences in designing a PowerShell function that reports on the size of the hidden .git folder. In that version of the function I decided to include a parameter that would permit the user to get the size pre-formatted as either KB, MB\u2026","rel":"","context":"In &quot;Git&quot;","block_context":{"text":"Git","link":"https:\/\/jdhitsolutions.com\/blog\/category\/git\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/image_thumb-29.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/image_thumb-29.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/image_thumb-29.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/01\/image_thumb-29.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":2403,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2403\/working-with-access-rules-in-powershell\/","url_meta":{"origin":685,"position":3},"title":"Working with Access Rules in PowerShell","author":"Jeffery Hicks","date":"June 22, 2012","format":false,"excerpt":"Yesterday I posted a function to create a summary report of ACL information using Windows PowerShell. I posted this in response to a question in the Ask Don and Jeff forum at PowerShell.com. I received an appreciative followup. The next step for this IT Pro it seems is to get\u2026","rel":"","context":"In &quot;Scripting&quot;","block_context":{"text":"Scripting","link":"https:\/\/jdhitsolutions.com\/blog\/category\/scripting\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":6855,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell-7\/6855\/powershell-scripting-for-linux-is-still-about-the-objects\/","url_meta":{"origin":685,"position":4},"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":8400,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8400\/friday-fun-custom-grouping-with-powershell\/","url_meta":{"origin":685,"position":5},"title":"Friday Fun &#8211; Custom Grouping with PowerShell","author":"Jeffery Hicks","date":"May 14, 2021","format":false,"excerpt":"The other day I was answering a question in the PowerShell Facebook group. This person was getting data from Active Directory and trying to organize the results in a way that met his business requirements. My suggestion was to use Group-Object and a custom grouping property. I am assuming you\u2026","rel":"","context":"In &quot;Active Directory&quot;","block_context":{"text":"Active Directory","link":"https:\/\/jdhitsolutions.com\/blog\/category\/active-directory\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/custom-grouping.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/custom-grouping.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/custom-grouping.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/custom-grouping.png?resize=700%2C400&ssl=1 2x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/685","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=685"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/685\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}