{"id":13511,"date":"2011-06-26T00:01:00","date_gmt":"2011-06-26T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2011\/06\/26\/dont-write-scripts-write-powershell-functions\/"},"modified":"2011-06-26T00:01:00","modified_gmt":"2011-06-26T00:01:00","slug":"dont-write-scripts-write-powershell-functions","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/dont-write-scripts-write-powershell-functions\/","title":{"rendered":"Don&#039;t Write Scripts, Write PowerShell Functions"},"content":{"rendered":"<p><b>Summary<\/b>: There are times when piling Windows PowerShell cmdlets together becomes a bit cumbersome, so instead of writing a script, consider functions.<\/p>\n<h2><strong>Weekend Scripter<\/strong><\/h2>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. There are times, when I want to do things that are a bit more complicated than piecing together cmdlets in a straightforward manner. In <a target=\"_blank\" href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/07\/08\/use-powershell-to-get-the-number-of-the-week-of-the-year.aspx\">yesterday&rsquo;s Hey! Scripting Guy blog<\/a>, I talked about not needing to write Windows PowerShell scripts. I illustrated piping cmdlets together, and working in an interactive fashion. <\/p>\n<p>I actually had the idea for this series while I was speaking at the <a target=\"_blank\" href=\"http:\/\/blogs.technet.com\/b\/johnbaker\/archive\/2011\/06\/07\/trip-report-on-techstravaganza-atlanta-2011.aspx\">TechStravaganza<\/a> in Atlanta, Georgia a month or so ago. I told them, that I was making an announcement to ITPros that it was time to quit writing scripts. Here is a picture taken of me while I was speaking on that occasion. In the picture, you can see Mark Schill, president of the <a target=\"_blank\" href=\"http:\/\/www.powershellgroup.org\/atlanta.ga\">Atlanta PowerShell User Group<\/a> on the left, and Mark Minassi sitting in the front row center. <\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8512.hsg-6-26-11-1_65721904.jpg\"><img decoding=\"async\" height=\"231\" width=\"404\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1258.hsg-6-26-11-1_thumb_1E1CC312.jpg\" alt=\"Photo of Ed speaking\" border=\"0\" title=\"Photo of Ed speaking\" style=\"padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px\" \/><\/a><\/p>\n<p>In the old days, I might very well whip out a script editor and bang out a simple Windows PowerShell script. This was especially true in the Windows PowerShell 1.0 days. For example, consider a common need: to view information about disk drives on a local or remote computer. The information I normally need is things like the capacity of the drive and the amount of free space. In addition, I like to know the percentage of free space on the drive because it gives me a &ldquo;feel&rdquo; for how rapidly my drive space is diminishing over time. Anyway, such a script is the DiskDriveScript.ps1 Windows PowerShell script. It is shown here. <\/p>\n<blockquote>\n<p><b>DiskDriveScript.ps1<\/b><\/p>\n<p><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">$drive = &#8220;c:&#8221;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">$computername = &#8220;.&#8221;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\">&nbsp;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;<\/span><\/span><span>Foreach($d in $drive)<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;<\/span><\/span><span>{<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp; <\/span><\/span><span>Get-WmiObject -Class win32_Volume -ComputerName $computername `<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span>-Filter &#8220;DriveLetter = &#8216;$d'&#8221; |<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp; <\/span><\/span><span>Format-table -autosize -property DriveLetter, Label, <\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp; <\/span><\/span><span>@{Name = &#8220;ComputerName&#8221;; Expression = {$_.__Server} },<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp; <\/span><\/span><span>@{Name = &#8220;Capacity(GB)&#8221;; Expression = {$_.capacity \/ 1GB} }, <\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp; <\/span><\/span><span>@{Name = &#8220;FreeSpace(GB)&#8221;; Expression = {$_.Freespace \/ 1GB} },<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp; <\/span><\/span><span>@{Name = &#8220;PercentFree&#8221;; Expression = { ($_.FreeSpace \/ $_.Capacity)*100 } }<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.25pt;list-style-type: disc;margin: 0in 0in 8pt\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span style=\"color: #000000\"><span><span>&nbsp;<\/span><\/span><span>} # end foreach<\/span><\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>The DiskDriveScript.ps1 is not a bad script. It has default values for the disk drive and the computer name. It will accept an array of drive letters, and it creates a nice custom formatted table of output. In addition, it calculates the percent of free space, and it displays the disk space in gigabytes, which is a number that is more likely to be meaningful with today&rsquo;s drive sizes. <\/p>\n<p>However, there are a number of problems with the DiskDriveScript.ps1 script. The main problem is that it is pretty much single purpose. Although I can call the script and redirect the output to a text file, that is about as far as I can go with the script. One reason is that it outputs data in a table. When the WMI <b>Win32_Volume<\/b> object hits the <b>Format-Table<\/b> cmdlet it changes from a management object to a series of format-specific objects. Once a <b>Format-Table<\/b>, <b>Format-List<\/b>, or <b>Format-Wide<\/b> cmdlet enters the equation, it becomes the end of the pipeline&mdash;nothing else can follow. In creating the table from within the DiskDriveScript.ps1 script, any potential code reuse is no longer possible. <\/p>\n<p>A more useful approach, and one that takes very little additional work, creates an advanced function instead of a single purpose script. An advanced function does require comment-based Help, but because comment-based Help is so easy to add (especially by using my <a target=\"_blank\" href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2010\/09\/11\/automatically-add-comment-based-help-to-your-powershell-scripts.aspx\">Add-Help add on to the Windows PowerShell ISE<\/a>), and because it adds so much value to your function (by explaining it and illustrating potential ways to use the function), I pretty much feel that it is nearly a requirement for an advanced function. This is why I emphasized comment-based Help during the 2011 Scripting Games. <\/p>\n<p>The big change from the DiskDrive.ps1 script was real simple&mdash;I changed <b>Format-Table<\/b> to <b>Select-Object<\/b>. That is it. That simple change converts the script from a single purpose, limited-use script into a script that emits an object that is available for nearly an infinite amount of code reuse.<\/p>\n<p>For example, suppose I am interested in the amount of free space I have on the various drives that are connected to my computer. I can use the <b>Get-DiskDrive<\/b> function to retrieve drive information, and then pipe the output to the <b>Sort-Object<\/b> cmdlet. This command is shown here. <\/p>\n<blockquote>\n<p><span lang=\"EN\" style=\"line-height: normal;list-style-type: disc\"><span style=\"font-family: Lucida Sans Typewriter\"><span>Get-DiskDrive -d c:,e:,g: | Sort-Object -Property percentFree<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>The command and its associated output are shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1323.hsg-6-26-11-2_59DC5BC5.png\"><img decoding=\"async\" height=\"469\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4478.hsg-6-26-11-2_thumb_6BB8EF92.png\" alt=\"Image of command output\" border=\"0\" title=\"Image of command output\" style=\"padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px\" \/><\/a><\/p>\n<p>Perhaps I am interested in seeing information about how my drives are formatted. I can group the drives, based on the <b>FileSystem<\/b> property. This command and its associated output are shown here.<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>PS C:\\Users\\ed&gt; Get-DiskDrive -d c:,e:,g: | Group-Object -Property FileSystem -NoElement<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>Count Name<\/span><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&#8212;&#8211; &#8212;-<\/span><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>2 NTFS<\/span><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>1 FAT32<\/span><\/span><\/span><span lang=\"EN\"><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>If I want a bit more information, I remove the <i>NoElement<\/i> parameter. The command and output associated with the revised command are shown here.<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>PS C:\\Users\\ed&gt; Get-DiskDrive -d c:,e:,g: | Group-Object -Property FileSystem <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>Count Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Group<\/span><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&#8212;&#8211; &#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8211;<\/span><span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>2 NTFS<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{@{DriveLetter=C:; Label=; FileSystem=NTFS; PageFilePrese&#8230;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>1 FAT32<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{@{DriveLetter=G:; Label=TESTFORMAT; FileSystem=FAT32; <\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>Maybe I need to know where the page file resides so I can optimize my system. Well, to do that, I add a <b>Where-Object<\/b> as shown here.<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>PS C:\\Users\\ed&gt; Get-DiskDrive -d c:,e:,g: | where { $_.pagefilepresent }<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>DriveLetter<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: C:<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>Label<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>FileSystem<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: NTFS<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>PageFilePresent : True<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>ComputerName<span>&nbsp;&nbsp;&nbsp; <\/span>: NEWMRED<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>Capacity(GB)<span>&nbsp;&nbsp;&nbsp; <\/span>: 119.142574310303<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>FreeSpace(GB)<span>&nbsp;&nbsp; <\/span>: 72.1981544494629<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>PercentFree<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span>: 60.5981152139833<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>But, maybe I need to know the percentage of free space, the file system, and the drive letter. I add a <b>Select-Object<\/b> command as shown here.<\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>PS C:\\Users\\ed&gt; Get-DiskDrive -d c:,e:,g: | where { $_.pagefilepresent } | select DriveLetter, Filesystem, percentFree<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>DriveLetter<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>FileSystem<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>PercentFree<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>&#8212;&#8212;&#8212;&#8211;<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;&#8211;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>C:<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>NTFS<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>60.5981152139833<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>If I want to do so, I can even use WMI to retrieve a list of all the drives on the computer that are fixed local hard disk drives, and pipe that information to the <b>Get-DiskDrive<\/b> function. This command is shown here (the <b>%<\/b> character is an alias for the <b>ForEach-Object<\/b> cmdlet). <\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>gwmi win32_logicaldisk -filter &#8220;drivetype = &#8216;3&#8217;&#8221; | % {Get-DiskDrive -drive $_.deviceID }<\/span><\/span><\/span><\/p>\n<\/blockquote>\n<p>The complete <b>Get-DiskDrive<\/b> advanced function is shown here. <\/p>\n<blockquote>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>Function Get-DiskDrive<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span>{<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp; <\/span><\/span><span>&lt;#<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp; <\/span><\/span><span>.Synopsis<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>This function returns capacity and freespace in gigs, and percent free<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp; <\/span><\/span><span>.Description<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>This function returns capacity and freespace in gigs, and percent free. By <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>default it returns the system drive (normally drive c:)<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp; <\/span><\/span><span>.Example<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Get-DiskDrive<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Returns capacity and free space in gigabytes. It also returns percent free,<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>and the drive letter and drive label of the system drive on the local machine.<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp; <\/span><\/span><span>.Example<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Get-DiskDrive -drive e: -computer berlin<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Returns capacity and free space in gigabytes of the e: drive. It also returns<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>percent free, and the drive letter and drive label of the system drive on the <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>remote machine named berlin.<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp; <\/span><\/span><span>.Example<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Get-DiskDrive -drive e: -computer berlin, munich<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Returns capacity and free space in gigabytes of the e: drive. It also returns<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>percent free, and the drive letter and drive label of the system drive on two <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>remote machines named berlin and munich.<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp; <\/span><\/span><span>.Example<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Get-DiskDrive -drive c:, e: -computer berlin, munich<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Returns capacity and free space in gigabytes of the C: and e: drive. It also <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>returns percent free, and the drive letter and drive label of the system drive <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>on two remote machines named berlin and munich.<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp; <\/span><\/span><span>.Example<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>&#8220;c:&#8221;,&#8221;d:&#8221;,&#8221;f:&#8221; | % { Get-DiskDrive $_ }<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Returns information about c, d, and f drives on local computer. <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp; <\/span><\/span><span>.Example<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Get-DiskDrive -d &#8220;c:&#8221;,&#8221;d:&#8221;,&#8221;f:&#8221;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Returns information about c, d, and f drives on local computer. Same command<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>as the previous example &#8211; but easier to read. But on my computer this is a <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>bit slower than the previous command (40 milliseconds).<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp; <\/span><\/span><span>.Parameter drive<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>The drive letter to query.<span>&nbsp; <\/span>Defaults to system drive (normally c:)<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp; <\/span><\/span><span>.Parameter computername<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>The name of the computer to query. Defaults to local machine. <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp; <\/span><\/span><span>.Notes<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>NAME:<span>&nbsp; <\/span>Example-<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>AUTHOR: ed wilson, msft<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>LASTEDIT: 06\/02\/2011 16:12:08<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>KEYWORDS:<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>HSG: HSG-06-26-2011<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp; <\/span><\/span><span>.Link<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span>Http:\/\/www.ScriptingGuys.com\/blog<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;<\/span><\/span><span>#Requires -Version 2.0<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;<\/span><\/span><span>#&gt;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;<\/span><\/span><span>Param(<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp; <\/span><\/span><span>[string[]]$drive = $env:SystemDrive,<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp; <\/span><\/span><span>[string[]]$computername = $env:COMPUTERNAME<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;<\/span><\/span><span>) #end param<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;<\/span><\/span><span>Foreach($d in $drive)<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;<\/span><\/span><span>{<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp; <\/span><\/span><span>Get-WmiObject -Class win32_Volume -ComputerName $computername -Filter &#8220;DriveLetter = &#8216;$d'&#8221; |<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp; <\/span><\/span><span>Select-object DriveLetter, Label, FileSystem, PageFilePresent, <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp; <\/span><\/span><span>@{Name = &#8220;ComputerName&#8221;; Expression = {$_.__Server} },<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp; <\/span><\/span><span>@{Name = &#8220;Capacity(GB)&#8221;; Expression = {$_.capacity \/ 1GB} }, <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp; <\/span><\/span><span>@{Name = &#8220;FreeSpace(GB)&#8221;; Expression = {$_.Freespace \/ 1GB} },<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp; <\/span><\/span><span>@{Name = &#8220;PercentFree&#8221;; Expression = { ($_.FreeSpace \/ $_.Capacity)*100 } }<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span style=\"font-family: Lucida Sans Typewriter\"><span><span>&nbsp;<\/span><\/span><span>} # end foreach<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"line-height: 13.5pt;list-style-type: disc;margin: 0in 0in 8pt;background: white\"><span lang=\"EN\"><span><span style=\"font-family: Lucida Sans Typewriter\"><span>&nbsp;<\/span><\/span><\/span><\/span><\/p>\n<p><span lang=\"EN\" style=\"line-height: normal;list-style-type: disc\"><span style=\"font-family: Lucida Sans Typewriter\"><span>} #end function get-diskdrive<\/span><\/span><\/span><\/p><\/blockquote>\n<p>The complete <b>Get-DiskDrive<\/b> function is uploaded to <a target=\"_blank\" href=\"http:\/\/gallery.technet.microsoft.com\/scriptcenter\/b0495304-90eb-4909-8079-1f38d4c20e05\">the Scripting Guys Script Repository<\/a>. This makes it easy to copy the function without worrying about getting transient HTML goop embedded in the code. <\/p>\n<p>I invite you to follow me on <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> and <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a>, or post your questions on the <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingforum\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: There are times when piling Windows PowerShell cmdlets together becomes a bit cumbersome, so instead of writing a script, consider functions. Weekend Scripter Microsoft Scripting Guy, Ed Wilson, is here. There are times, when I want to do things that are a bit more complicated than piecing together cmdlets in a straightforward manner. In [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[3,4,45,77],"class_list":["post-13511","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell","tag-writing"],"acf":[],"blog_post_summary":"<p>Summary: There are times when piling Windows PowerShell cmdlets together becomes a bit cumbersome, so instead of writing a script, consider functions. Weekend Scripter Microsoft Scripting Guy, Ed Wilson, is here. There are times, when I want to do things that are a bit more complicated than piecing together cmdlets in a straightforward manner. In [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/13511","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=13511"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/13511\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=13511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=13511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=13511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}