{"id":54483,"date":"2009-02-02T21:03:00","date_gmt":"2009-02-02T21:03:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2009\/02\/02\/hey-scripting-guy-how-can-i-tell-how-much-free-disk-space-a-user-has\/"},"modified":"2009-02-02T21:03:00","modified_gmt":"2009-02-02T21:03:00","slug":"hey-scripting-guy-how-can-i-tell-how-much-free-disk-space-a-user-has","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-how-can-i-tell-how-much-free-disk-space-a-user-has\/","title":{"rendered":"Hey, Scripting Guy! How Can I Tell How Much Free Disk Space a User Has?"},"content":{"rendered":"<h2><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\" \/> <\/h2>\n<p>I know most people have heard of <a href=\"http:\/\/encarta.msn.com\/encyclopedia_761563087_6\/Computer.html\" target=\"_blank\">Moore\u2019s Law<\/a> that is named after Gordon Moore, but have you ever heard of Bob\u2019s law? Bob was the senior network administrator when I first became an IT pro, and he created what he called Bob&#8217;s Law. Briefly stated it says this: &#8220;A user&#8217;s demand for storage space will always expand to meet the available storage space, plus 10 percent.&#8221; In other words, we can never have too much disk space for users. <\/p>\n<p>Well, at work, we are currently being ravaged by Bob\u2019s Law; our users are constantly running out of disk space on their work stations, their laptops, and even their Windows smart phones. I go into some offices, and they have USB sticks stuck in every available port on their laptops, and some users have even gone so far as to buy external USB hubs and stick stuff in there as well. The things look like some kind of infernal terminator porcupine. I know we cannot suspend Bob`s Law, but I need a script that I can run remotely that will tell me how much free disk space a user has. Can you help me? <\/p>\n<p>&#8211; EC<\/p>\n<p><img decoding=\"async\" height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\" \/><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\" \/><\/p>\n<p>Hi EC,<\/p>\n<p>So your users say they do not have enough free disk space? Tell them to open Windows PowerShell and type Format c\u2026just kidding. That command will delete all their files. That is an old IT joke, about as old as Bob\u2019s law.<\/p>\n<table class=\"dataTable\" id=\"E4C\" cellSpacing=\"0\" cellPadding=\"0\">\n<thead><\/thead>\n<tbody>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">This week is Desktop Week\u2014a rather vague series of loosely connected articles that may or may not be related to desktops. But the articles were written on a desktop, so maybe that counts. If you want to see some VBScript examples of Desktop Management scripts, check out <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/scripts\/desktop\/default.mspx\" target=\"_blank\">these scripts<\/a> in the Script Center Script Repository. The Community-Submitted Scripts Center also has a collection of scripts related to <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/csc\/scripts\/desktop\/default.mspx\" target=\"_blank\">desktop management<\/a>. In addition, there is the <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/desktop.mspx\" target=\"_blank\">Desktop Management archive<\/a> of \u201cHey Scripting Guy!\u201d articles, which include scripts and explanations as well. The scripts this week will be using Windows PowerShell. To download Windows PowerShell and to find getting started information, see the <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\" target=\"_blank\">Windows PowerShell hub<\/a>.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>To aid you in managing your users\u2019 incessant demands for disk space, it might be useful to be able to retrieve the amount of free disk space from a remote computer before it becomes a crisis. We can use the <b>Win32_LogicalDisk<\/b> WMI class with the <b>Get-WmiObject<\/b> cmdlet from Windows PowerShell. An example of doing this is seen in the <b>GetFreeDiskSpace.ps1<\/b> script.<\/p>\n<p><b>Get-FreeDiskSpace.ps1<\/b><\/p>\n<pre class=\"codeSample\">Function Get-FreeDiskSpace($drive,$computer)\n{\n $driveData = Get-WmiObject -class win32_LogicalDisk `\n -computername $computer -filter \"Name = '$drive'\"\n\"$computer free disk space on drive $drive\"\n\"{0:n2}\" -f ($driveData.FreeSpace\/1MB) + \" MegaBytes\"\n}\nGet-FreeDiskSpace -drive \"C:\" -computer \"vista\"\n<\/pre>\n<p>The&nbsp;first thing we do in the <b>Get-FreeDiskSpace.ps1<\/b> script is to create a function. To create a function that uses multiple input parameters we use the <b>Function<\/b> keyword, specify the name of the function, use variables for each input parameter, and define the script block within the curly brackets.<\/p>\n<p>The <b>Get-FreeDiskSpace.ps1<\/b> script begins with the <b>Function<\/b> keyword, the name of the function, and the two input parameters. The first input parameter is the drive name, and the second is the name of the computer. The input parameters are placed inside smooth parentheses with a variable used to hold the data that comes in when the function is called:<\/p>\n<pre class=\"codeSample\">Function Get-FreeDiskSpace($drive,$computer)\n{\n<\/pre>\n<p>Inside the curly brackets the <b>Get-FreeDiskSpace<\/b> function uses the <b>Get-WmiObject<\/b> cmdlet to query the <b>Win32_LogicalDisk<\/b> WMI class. It connects to the computer specified in the <b>$computer<\/b> parameter, and it filters out only the drive that is specified in the <b>$drive<\/b> parameter. When the function is called, the parameters are specified as <b>\u2013drive<\/b> and <b>\u2013computer<\/b>. In the function definition, the variables <b>$drive<\/b> and <b>$computer<\/b> are used to hold the values supplied to the parameters.<\/p>\n<p>The <b>\u2013filter<\/b> parameter from the <b>Get-WmiObject<\/b> cmdlet is used to limit the number of instances that are returned by the WMI query. The filter takes the place of the <b>where<\/b>clause from VBScript WMI Query Language (WQL) statements. The filter in our script limits the number of instances that are returned to only the one specified in the <b>$drive<\/b> variable. Here is our filter:<\/p>\n<pre class=\"codeSample\">-filter \"Name = '$drive'<\/pre>\n<p>The thing that is perhaps surprising is that the value contained in the <b>$drive<\/b> variable still gets read. You may recall from previous \u201cHey, Scriting Guy!\u201d articles that I went on and on at great length about the difference between literal quotation marks and expanding quotation marks. We also have this documented as a <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/pstips\/jun07\/pstip0615.mspx\" target=\"_blank\">Windows PowerShell tip<\/a>. Well, you can forget that here. When you are working with the <b>filter<\/b> parameter of the <b>Get-WmiObject<\/b> cmdlet, you are using WQL syntax, not Windows PowerShell syntax. This is why you use the equal sign instead of <b>\u2013eq<\/b>. It is also why the single quotation mark is not a literal quotation mark, so we still have access to the value of the <b>$drive<\/b> variable.<\/p>\n<p>An excellent reference for learning WMI is the Microsoft Press book, <a href=\"http:\/\/www.microsoft.com\/learning\/en\/us\/books\/8853.aspx\" target=\"_blank\">Microsoft Windows Scripting with WMI: Self-Paced Learning Guide<\/a>. While the examples are all written in VBScript, WMI technology is still the same.<\/p>\n<p>If we were to use the <b>Get-WmiObject<\/b> cmdlet by itself and query the <b>Win32_Logicaldisk<\/b> WMI class, we would see an output similar to this:<\/p>\n<p><img decoding=\"async\" height=\"352\" alt=\"Output of the Win32_Logicaldisk WMI class queried by the Get-WmiObject cmdlet\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2009\/february\/hey0202\/hsg_2_2_09-01.jpg\" width=\"500\" border=\"0\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>There is more data returned from the WMI query than that which is displayed in the preceding image. Windows PowerShell creates s a nice display of information that is considered to be most useful to the network administrator. If you want to see more information, you can easily obtain it by using either the methods or properties seen in Table 1. <\/p>\n<p>After the data from WMI is retrieved, it is stored in the <b>$driveData<\/b> variable. The data that is stored in the <b>$driveData<\/b> variable is an instance of the <b>Win32_LogicalDisk<\/b>. This variable contains a complete instance of the class. The members of this class are seen in Table 1.<\/p>\n<p><b>Table 1 Members of the Win32_LogicalDisk class<\/b><\/p>\n<table class=\"dataTable\" id=\"EXH\" cellSpacing=\"0\" cellPadding=\"0\">\n<thead>\n<tr class=\"stdHeader\" vAlign=\"top\">\n<td class=\"\" id=\"colEZH\">Name<\/td>\n<td class=\"\" id=\"colE4H\">Member Type<\/td>\n<td class=\"\" id=\"colECAAC\">Definition<\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">Chkdsk<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Management.ManagementBaseObject Chkdsk(System.Boolean FixErrors, System.Boolean VigorousIndexCheck, System.Boolean SkipFolderCycle, System.Boolean ForceDismount, System.Boolean RecoverBadSectors, System.Boolean OkToRunAtBootUp)<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">Reset<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Management.ManagementBaseObject Reset()<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">SetPowerState<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Method<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Management.ManagementBaseObject SetPowerState(System.UInt16 PowerState, System.String Time)<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">Access<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.UInt16 Access {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">Availability<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.UInt16 Availability {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">BlockSize<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.UInt64 BlockSize {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">Caption<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String Caption {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">Compressed<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Boolean Compressed {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">ConfigManagerErrorCode<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.UInt32 ConfigManagerErrorCode {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">ConfigManagerUserConfig<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Boolean ConfigManagerUserConfig {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">CreationClassName<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String CreationClassName {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">Description<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String Description {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">DeviceID<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String DeviceID {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">DriveType<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.UInt32 DriveType {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">ErrorCleared<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Boolean ErrorCleared {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">ErrorDescription<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String ErrorDescription {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">ErrorMethodology<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String ErrorMethodology {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">FileSystem<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String FileSystem {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">FreeSpace<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.UInt64 FreeSpace {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">InstallDate<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String InstallDate {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">LastErrorCode<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.UInt32 LastErrorCode {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">MaximumComponentLength<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.UInt32 MaximumComponentLength {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">MediaType<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.UInt32 MediaType {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">Name<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String Name {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">NumberOfBlocks<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.UInt64 NumberOfBlocks {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">PNPDeviceID<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String PNPDeviceID {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">PowerManagementCapabilities<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.UInt16[] PowerManagementCapabilities {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">PowerManagementSupported<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Boolean PowerManagementSupported {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">ProviderName<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String ProviderName {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">Purpose<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String Purpose {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">QuotasDisabled<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Boolean QuotasDisabled {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">QuotasIncomplete<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Boolean QuotasIncomplete {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">QuotasRebuilding<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Boolean QuotasRebuilding {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">Size<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.UInt64 Size {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">Status<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String Status {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">StatusInfo<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.UInt16 StatusInfo {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">SupportsDiskQuotas<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Boolean SupportsDiskQuotas {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">SupportsFileBasedCompression<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Boolean SupportsFileBasedCompression {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">SystemCreationClassName<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String SystemCreationClassName {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">SystemName<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String SystemName {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">VolumeDirty<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Boolean VolumeDirty {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">VolumeName<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String VolumeName {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">VolumeSerialNumber<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<pre class=\"codeSample\">System.String VolumeSerialNumber {get;set;}<\/pre>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">__CLASS<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String __CLASS {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">__DERIVATION<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String[] __DERIVATION {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">__DYNASTY<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String __DYNASTY {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">__GENUS<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Int32 __GENUS {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">__NAMESPACE<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String __NAMESPACE {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">__PATH<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String __PATH {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">__PROPERTY_COUNT<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Int32 __PROPERTY_COUNT {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">__RELPATH<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String __RELPATH {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">__SERVER<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String __SERVER {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">__SUPERCLASS<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">Property<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.String __SUPERCLASS {get;set;}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">PSStatus<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">PropertySet<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">PSStatus {Status, Availability, DeviceID, StatusInfo}<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">ConvertFromDateTime<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">ScriptMethod<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Object ConvertFromDateTime();<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\">ConvertToDateTime<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">ScriptMethod<\/p>\n<\/td>\n<td class=\"\">\n<p class=\"lastInCell\">System.Object ConvertToDateTime();<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>After you have the data stored in the <b>$driveData<\/b> variable, you will want to print out some information to the user of the script. The first thing to do is print out the name of the computer and the name of the drive. To do this, you can place the variables inside double quotation marks. Double quotation marks are expanding strings, and variables placed inside double quotation marks emit their value, not their name. This is seen here:<\/p>\n<pre class=\"codeSample\">\"$computer free disk space on drive $drive\"<\/pre>\n<p>The next thing you will want to do is to format the data that is returned. To do this, use the .NET Framework format strings to specify two decimal places. We will need to use smooth parentheses to force the evaluation of the free disk space prior to formatting it to two decimal places. This is seen here:<\/p>\n<pre class=\"codeSample\">\"{0:n2}\" -f ($driveData.FreeSpace\/1MB) + \" MegaBytes\"<\/pre>\n<p>When you run the script you see the name of the computer, the name of the drive, and the amount of free disk space expressed in megabytes:<\/p>\n<pre class=\"codeSample\">office free disk space on drive C:\n54,108.36 MegaBytes\n<\/pre>\n<p>Well, EC, that is about it for using WMI to obtain free disk space. Join us tomorrow as Desktop Week continues. Until then, peace.<\/p>\n<p>&nbsp;<\/p>\n<p><b>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I know most people have heard of Moore\u2019s Law that is named after Gordon Moore, but have you ever heard of Bob\u2019s law? Bob was the senior network administrator when I first became an IT pro, and he created what he called Bob&#8217;s Law. Briefly stated it says this: &#8220;A user&#8217;s demand for storage space [&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":[16,216,47,3,4,12,45,6],"class_list":["post-54483","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-desktop-management","tag-disk-drives-and-volumes","tag-general-management-tasks","tag-scripting-guy","tag-scripting-techniques","tag-storage","tag-windows-powershell","tag-wmi"],"acf":[],"blog_post_summary":"<p>I know most people have heard of Moore\u2019s Law that is named after Gordon Moore, but have you ever heard of Bob\u2019s law? Bob was the senior network administrator when I first became an IT pro, and he created what he called Bob&#8217;s Law. Briefly stated it says this: &#8220;A user&#8217;s demand for storage space [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/54483","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=54483"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/54483\/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=54483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=54483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=54483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}