{"id":56333,"date":"2008-01-28T03:48:00","date_gmt":"2008-01-28T03:48:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2008\/01\/28\/hey-scripting-guy-how-can-i-create-a-disk-quota-that-gives-the-user-unlimited-disk-space\/"},"modified":"2008-01-28T03:48:00","modified_gmt":"2008-01-28T03:48:00","slug":"hey-scripting-guy-how-can-i-create-a-disk-quota-that-gives-the-user-unlimited-disk-space","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-how-can-i-create-a-disk-quota-that-gives-the-user-unlimited-disk-space\/","title":{"rendered":"Hey, Scripting Guy! How Can I Create a Disk Quota That Gives the User Unlimited Disk Space?"},"content":{"rendered":"<h2><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\" \/> <\/h2>\n<p>Hey, Scripting Guy! Your article &#8220;<a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/topics\/win2003\/quotas.mspx\">Managing Disk Quotas in Windows Server 2003 and Windows XP<\/a>&#8221; is quite good but it leaves out one important detail: how can you specify an unlimited disk quota for a user?<\/p>\n<p>&#8212; CA<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\" \/><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\" \/><a href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><img decoding=\"async\" class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\" \/><\/a> <\/p>\n<p>Hey, CA. You know, it\u2019s funny. When we received this question, we had no idea what the answer was. In fact, we were just about to give up and pretend that we never even received CA\u2019s email when something absolutely amazing happened. At the same time we were trying to figure out how to create a disk quota with unlimited disk space, Scripting Guy Jean Ross was busy writing a Perl script that worked with dates and times. (In preparation for the <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/funzone\/games\/default.mspx\"><b>2008 Winter Scripting Games<\/b><\/a>, coming February 15<sup>th<\/sup> through March 3<sup>rd<\/sup> in the Script Center.) To be honest, Jean\u2019s first attempt at doing date arithmetic didn\u2019t go quite as planned; not only did the date arithmetic fail (turns out she left the semicolon off the end of the line), but the script also tore a gaping hole in the space-time continuum. And, lo and behold, who should come walking through that gaping hole but our very own Scripting Guy, Dean Tsaltas!<\/p>\n<p>Actually, we need to clarify that a little. This wasn\u2019t the Dean Tsaltas we all know and \u2026 love \u2026. Instead, it was a Dean Tsaltas from the future, from the year 2027, to be exact.<\/p>\n<p>\u201cHey, guys,\u201d said future Dean.<\/p>\n<p>\u201cHey,\u201d we said.<\/p>\n<p>\u201cI was outside shoveling snow in Nova Scotia \u2013 even July can be quite chilly in Halifax \u2013 when I noticed a hole in the space-time continuum. When I looked through it, I saw two things. First, Jean: you left a semicolon off line 4 in your Perl script. Second, Scripting Guy who writes that column: you\u2019re having problems creating a disk quota that allows the user unlimited disk space. Well, you don\u2019t have you wrack your brain trying to figure that out anymore; I brought you an answer from the future.\u201d<\/p>\n<p>Needless to say, the Scripting Guy who writes this column was extremely excited, at least until he saw what Dean had handed him. \u201cUm, Dean, this is a <i>Hey, Scripting Guy!<\/i> column from the year 2006. Not only that, but it doesn\u2019t even have anything to do with disk quotas; it\u2019s about inserting text into an existing Microsoft Word bookmark!\u201d<\/p>\n<p>\u201cReally?\u201d said Dean. \u201cHold on a second; let me do a search on this topic. Wow. Here\u2019s what we got back: nothing. Apparently there\u2019s no way to create a disk quota that allows the user unlimited disk space, not even in the future. Sorry, guys.\u201d<\/p>\n<p>Well, needless to say, the word \u201cnothing\u201d means absolutely nothing to the Scripting Guys. Did we give up on our quest to write a script that can create a disk quota that gives the user unlimited disk space? No way; after all, this was our chance to change the course of history! And, after digging around in the bowels of WMI for awhile, that\u2019s exactly what we did. We changed the course of history:<\/p>\n<pre class=\"codeSample\">Const No_Limit = \"18446744073709551615\"\n\nstrComputer = \".\"\n\nSet objWMIService = GetObject(\"winmgmts:\\\\\" &amp; strComputer &amp; \"\\root\\cimv2\")\n\nSet objAccount = objWMIService.Get _\n    (\"Win32_Account.Domain='fabrikam',Name='kenmyer'\")\nSet objDisk = objWMIService.Get _\n    (\"Win32_LogicalDisk.DeviceID='D:'\")\nSet objQuota = objWMIService.Get _\n    (\"Win32_DiskQuota\").SpawnInstance_\n\nobjQuota.QuotaVolume = objDisk.Path_.RelPath\nobjQuota.User = objAccount.Path_.RelPath\nobjQuota.Limit = No_Limit\nobjQuota.WarningLimit = No_Limit \nobjQuota.Put_\n<\/pre>\n<p>First of all, we should point out that this isn\u2019t some strange, futuristic scripting language; this is still good old VBScript, circa 2008. For better or worse, however, WMI disk quota scripts tend to have a &#8230; unique \u2026 look to them. So don\u2019t worry. You don\u2019t have to wait until the year 2027 to run this script; it should work just fine on your present-day machines.<\/p>\n<table id=\"EZD\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<thead><\/thead>\n<tbody>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p><b>Note<\/b>. Actually, this script isn\u2019t half as crazy looking as it <i>could<\/i> be. For example, here\u2019s a line of code from a script that deletes a disk quota entry:<\/p>\n<pre class=\"codeSample\">Set objQuota = objWMIService.Get _\n    (\"Win32_DiskQuota.QuotaVolume='Win32_LogicalDisk.DeviceID=\" &amp; chr(34) &amp; strDrive &amp; chr(34) &amp; \"',\" &amp; _\n        \"User='Win32_Account.Domain=\" &amp; chr(34) &amp; strDomain &amp; chr(34) &amp; _\n            \",Name=\" &amp; chr(34) &amp; strUser &amp; chr(34) &amp; \"'\")\n<\/pre>\n<p>Count your blessings!<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>As you can see, we start out by defining a constant named No_Limit and setting the value to 18446744073709551615; it goes without saying that, if you set the disk quota <b>Limit<\/b> and <b>WarningLimit<\/b> properties to 18446744073709551615, you\u2019ll end up configuring these property values as <i>No limit<\/i>.<\/p>\n<table id=\"EUE\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<thead><\/thead>\n<tbody>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\"><b>Note<\/b>. To tell you the truth, we have no idea where the value 18446744073709551615 (a little more than 18 quintillion) came from. According to future Dean, however, sometime in the year 2027 the Scripting Guys will record their 18 quintillionth inquiry about the <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/tools\/admatic.mspx\"><b>Active Directory browser<\/b><\/a>. Coincidence? Maybe. But, then again, maybe not.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>After defining the constant No_Limit we connect to the WMI service on the local computer. Can we run this same script against a remote computer? You bet we can; all we have to do is assign the name of the remote computer to the variable strComputer. For example:<\/p>\n<pre class=\"codeSample\">strComputer = \"atl-fs-001\"\n<\/pre>\n<p>Next we need to create a trio of objects:<\/p>\n<pre class=\"codeSample\">Set objAccount = objWMIService.Get _\n    (\"Win32_Account.Domain='fabrikam',Name='kenmyer'\")\nSet objDisk = objWMIService.Get _\n    (\"Win32_LogicalDisk.DeviceID='D:'\")\nSet objQuota = objWMIService.Get _\n    (\"Win32_DiskQuota\").SpawnInstance_\n<\/pre>\n<p>In line 1 we\u2019re creating an object reference to the user who is about to get a new disk quota. This involves using WMI\u2019s <b>Get<\/b> method to retrieve an instance of the <b>Win32_Account<\/b> class, an instance \u2013 in this case, anyway \u2013 where the <b>Domain<\/b> property is equal to <i>fabrikam<\/i> and the <b>Name<\/b> (logon name) property is equal to <i>kenmyer<\/i>.<\/p>\n<p>In the second line, we\u2019re creating an object reference to the <b>Win32_LogicalDisk<\/b> class. Here we simply specify the <b>DeviceID<\/b> of the drive where the quota should be created. Because we want the quota to be created on drive D we assign DeviceID the value <i>D:<\/i> (note the colon on the end).<\/p>\n<p>Finally, we create an object reference to the <b>Win32_DiskQuota<\/b> class, then use the <b>SpawnInstance_<\/b> method to generate a new, blank disk quota. At this point, we\u2019re ready to assign some values to the properties of our new disk quota.<\/p>\n<p>To do that, we first use these two lines of code to specify the quota volume and the user account:<\/p>\n<pre class=\"codeSample\">objQuota.QuotaVolume = objDisk.Path_.RelPath\nobjQuota.User = objAccount.Path_.RelPath\n<\/pre>\n<p>As you can see, in each case we use the <b>Path_.RelPath<\/b> property of our object reference when assigning the property values. Why? Well, if we <i>didn\u2019t<\/i> use the RelPath (relative path) property we\u2019d have to pass the following value to the <b>User<\/b> property:<\/p>\n<pre class=\"codeSample\">Win32_UserAccount.Domain=\"fabrikam\",Name=\"kenmyer\"\n<\/pre>\n<p>Of course, this entire string \u2013 quotation marks and all \u2013 must be enclosed in another set of quotation marks. If you have any experience at all with VBScript then you know how much \u2026 fun \u2026 it can be to enclose quotation marks inside of quotation marks. Fortunately, the value of the Path_.RelPath property happens to be this:<\/p>\n<pre class=\"codeSample\">Win32_UserAccount.Domain=\"fabrikam\",Name=\"kenmyer\"\n<\/pre>\n<p>Look familiar? <i>That\u2019s<\/i> why we use RelPath. <\/p>\n<p>After taking care of the QuotaVolume and User properties we then use these two lines of code (and our constant, No_Limit) to set both the Limit and WarningLimit properties to, well, no limit:<\/p>\n<pre class=\"codeSample\">objQuota.Limit = No_Limit\nobjQuota.WarningLimit = No_Limit\n<\/pre>\n<p>Once we\u2019ve finished assigning property values we call the <b>Put_<\/b> method to write the new disk quota to drive D:<\/p>\n<pre class=\"codeSample\">objQuota.Put_\n<\/pre>\n<p>Is that really going to work? Well, let\u2019s take a look:<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Disk Quotas\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/nolimit.jpg\" width=\"516\" height=\"261\" \/> <\/p>\n<p>How \u2018bout that?<\/p>\n<p>That should do it, CA. As for the Scripting Guys, we had many more questions for future Dean, but he wasn\u2019t able to stay. \u201cI have to get back,\u201d he said. \u201cThat snow won\u2019t shovel itself.<\/p>\n<p>\u201cOh, wait: I guess in the future the snow <i>does<\/i> shovel itself. But I better get back anyway.\u201d And with that, he was gone.<\/p>\n<p>But that\u2019s OK; we expect to see future Dean again, and probably sooner rather than later. After all, Jean <i>is<\/i> still working on those Perl scripts.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! Your article &#8220;Managing Disk Quotas in Windows Server 2003 and Windows XP&#8221; is quite good but it leaves out one important detail: how can you specify an unlimited disk quota for a user? &#8212; CA Hey, CA. You know, it\u2019s funny. When we received this question, we had no idea what the [&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":[708,3,12,5],"class_list":["post-56333","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-disk-quotas","tag-scripting-guy","tag-storage","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! Your article &#8220;Managing Disk Quotas in Windows Server 2003 and Windows XP&#8221; is quite good but it leaves out one important detail: how can you specify an unlimited disk quota for a user? &#8212; CA Hey, CA. You know, it\u2019s funny. When we received this question, we had no idea what the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/56333","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=56333"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/56333\/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=56333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=56333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=56333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}