{"id":1333,"date":"2009-04-02T05:00:24","date_gmt":"2009-04-02T13:00:24","guid":{"rendered":"http:\/\/www.sapien.com\/blog\/2009\/04\/02\/april-one-liner\/"},"modified":"2009-04-02T08:29:58","modified_gmt":"2009-04-02T16:29:58","slug":"april-one-liner","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2009\/04\/02\/april-one-liner\/","title":{"rendered":"April One-Liner"},"content":{"rendered":"<p>Here&#8217;s another way to get disk utilization using your PSDrives. This is a one line command.\u00a0 I&#8217;ve broken it up with the line continuation character. This only works locally, only queries PSDrives using the FileSystem provider and that<br \/>\nhave a value for the Used property.<\/p>\n<div style=\"font-size: 8pt; margin: 20px 0px 10px; overflow: auto; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border: gray 1px solid; padding: 4px;\">\n<div style=\"font-size: 8pt; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;\">\n<pre style=\"font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;\">Get-PSDrive -PSProvider filesystem | where {$_.used} |<\/pre>\n<pre style=\"font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;\">select Root,@{name=<span style=\"color: #006080\">\"Size(GB)\"<\/span>;expression={($_.used+$_.free)\/1GB -as [int]}},`<\/pre>\n<pre style=\"font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;\">@{name=<span style=\"color: #006080\">\"Used(GB)\"<\/span>;expression={<span style=\"color: #006080\">\"{0:F2}\"<\/span> -f ($_.used\/1GB)}},`<\/pre>\n<pre style=\"font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;\">@{name=<span style=\"color: #006080\">\"Free(GB)\"<\/span>;expression={<span style=\"color: #006080\">\"{0:F2}\"<\/span> -f ($_.free\/1GB)}},`<\/pre>\n<pre style=\"font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;\">@{name=<span style=\"color: #006080\">\"PercentFree\"<\/span>;expression={<span style=\"color: #006080\">\"{0:P2}\"<\/span> -f ($_.free\/($_.used+$_.free))}}<\/pre>\n<\/div>\n<\/div>\n<p>The only thing I&#8217;ve done is customize the output to show utilization sizes in GB and calculate a PercentFree value. The expression returns information like this:<\/p>\n<p><span style=\"font-size: x-small; color: #0000ff; font-family: Consolas;\">Root\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : C:\\<br \/>\nSize(GB)\u00a0\u00a0\u00a0 : 75<br \/>\nUsed(GB)\u00a0\u00a0\u00a0 : 66.80<br \/>\nFree(GB)\u00a0\u00a0\u00a0 : 7.73<br \/>\nPercentFree : 10.37 % <\/span><\/p>\n<p><span style=\"font-size: x-small; color: #0000ff; font-family: Consolas;\">Root\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : F:\\<br \/>\nSize(GB)\u00a0\u00a0\u00a0 : 75<br \/>\nUsed(GB)\u00a0\u00a0\u00a0 : 7.53<br \/>\nFree(GB)\u00a0\u00a0\u00a0 : 67.00<br \/>\nPercentFree : 89.90 %<\/span><\/p>\n<p>You could also pipe this expression to <strong>Format-Table<\/strong> to make a nicer looking report.<\/p>\n<div id=\"scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:7ebb9d2a-ab28-4dd4-be44-eed781507a2a\" class=\"wlWriterSmartContent\" style=\"padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px\">\n<p>Download the oneliner <a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2009\/04\/april09-oneliner.txt\" target=\"_blank\">here.<\/a><\/p>\n<p>UPDATE: Since I originally posted this I realized I made a grievous error. This oneliner likely won&#8217;t work for you, and definitely not on PowerShell v1.0. I normally test on all versions but missed something this month. My apologies. Here is a comparable expression that uses WMI to achieve the same results.<br \/>\n<code><br \/>\nget-wmiobject win32_logicaldisk -filter \"size &gt; 0\" |<br \/>\nselect DeviceID,@{name=\"Size(GB)\";expression={($_.size)\/1GB -as [int]}},`<br \/>\n@{name=\"Used(GB)\";expression={<br \/>\n\"{0:F2}\" -f ((((($_.size\/1mb) - ($_.freespace\/1mb))*1mb)\/1gb))}},`<br \/>\n@{name=\"Free(GB)\";expression={\"{0:F2}\" -f ($_.freespace\/1GB)}},`<br \/>\n@{name=\"PercentFree\";expression={\"{0:P2}\" -f ($_.freespace\/$_.size)}}<\/div>\n<p><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s another way to get disk utilization using your PSDrives. This is a one line command.\u00a0 I&#8217;ve broken it up with the line continuation character. This only works locally, only queries PSDrives using the FileSystem provider and that have a value for the Used property. Get-PSDrive -PSProvider filesystem | where {$_.used} | select Root,@{name=&#8221;Size(GB)&#8221;;expression={($_.used+$_.free)\/1GB -as [&hellip;]<\/p>\n","protected":false},"author":3,"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,"footnotes":""},"categories":[25],"tags":[28,489],"class_list":["post-1333","post","type-post","status-publish","format-standard","hentry","category-windows-powershell","tag-powershell","tag-psdrive"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/1333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=1333"}],"version-history":[{"count":2,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/1333\/revisions"}],"predecessor-version":[{"id":1334,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/1333\/revisions\/1334"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=1333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=1333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=1333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}