<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Reserve Space on the Datastore in VMware PowerCLI Discussions</title>
    <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Reserve-Space-on-the-Datastore/m-p/321784#M3291</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could use a mutual exclusion to prevent both programs to run at the same time. You can use the following code and wrap it around your programs:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;PRE&gt;&lt;SPAN style="color: #0000FF;"&gt;Try&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; {
&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$MutexName&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #FF0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800000;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="color: #800000;"&gt;Global\Mutex&lt;/SPAN&gt;&lt;SPAN style="color: #800000;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;

&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;#&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt; Start mutual exclusion&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$Mutex&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #FF0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #5F9EA0; font-weight: bold;"&gt;New-Object&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #5F9EA0; font-style: italic;"&gt;-TypeName&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800000;"&gt;System.Threading.Mutex&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #5F9EA0; font-style: italic;"&gt;-ArgumentList&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$false&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$MutexName&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;
&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$Mutex&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;.WaitOne()

&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;#
&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;#&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt; Your program comes here&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;#
&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; 
&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;#&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt; Stop mutual exclusion&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$Mutex&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;.ReleaseMutex()
&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$Mutex&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #FF0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$null&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;
}
&lt;/SPAN&gt;&lt;SPAN style="color: #0000FF;"&gt;Catch&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; { 
&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;#&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt; Stop mutual exclusion&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$Mutex&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;.ReleaseMutex()
&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$Mutex&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #FF0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$null&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;
}&lt;/SPAN&gt;

&lt;/PRE&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first program that runs will get the mutual exclusion and will continue. The second program will wait untill the first program relases the mutual exclusion. This prevents both programs to run at the same time. That will assure that if P2 runs it fails and stop execution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The Try - Catch construction ensures that if an error is generated in your code, the mutex is still released before the program stops.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards, Robert&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: RvdNieuwendijk Added the Try - Catch explanation.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 04 Mar 2012 16:21:59 GMT</pubDate>
    <dc:creator>RvdNieuwendijk</dc:creator>
    <dc:date>2012-03-04T16:21:59Z</dc:date>
    <item>
      <title>Reserve Space on the Datastore</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Reserve-Space-on-the-Datastore/m-p/321782#M3289</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Howdy All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Suppose if current freespace on the datastore is 200GB.&lt;/P&gt;&lt;P&gt;I have 2 programs, P1 and P2. Both needs a total of 150GB freespace to work on ( creating number of VMs and all. ) .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;P1 starts and checks for freespace. It succeeds and proceeds with his work.&lt;/P&gt;&lt;P&gt;At the same time,&lt;/P&gt;&lt;P&gt;P2 starts and checks for freespace, it also succeeds. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In situation like these, How can I reserve 150GB for P1 so that when P2 checks, It fails and stops execution.&lt;/P&gt;&lt;P&gt;Powercli - 4.1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Nikunj&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 04 Mar 2012 14:52:29 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Reserve-Space-on-the-Datastore/m-p/321782#M3289</guid>
      <dc:creator>NikunjB</dc:creator>
      <dc:date>2012-03-04T14:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: Reserve Space on the Datastore</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Reserve-Space-on-the-Datastore/m-p/321783#M3290</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you're going to be using the space anyway why not provision as thick disks and increase your write speed at the same time?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;----&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Optism Training&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.optismtraining.com/"&gt;www.optismtraining.com&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Personal &amp;amp; Enterprise VMware Lab Rentals and training services.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 04 Mar 2012 15:00:27 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Reserve-Space-on-the-Datastore/m-p/321783#M3290</guid>
      <dc:creator>OptismTraining</dc:creator>
      <dc:date>2012-03-04T15:00:27Z</dc:date>
    </item>
    <item>
      <title>Re: Reserve Space on the Datastore</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Reserve-Space-on-the-Datastore/m-p/321784#M3291</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could use a mutual exclusion to prevent both programs to run at the same time. You can use the following code and wrap it around your programs:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;PRE&gt;&lt;SPAN style="color: #0000FF;"&gt;Try&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; {
&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$MutexName&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #FF0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800000;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="color: #800000;"&gt;Global\Mutex&lt;/SPAN&gt;&lt;SPAN style="color: #800000;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;

&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;#&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt; Start mutual exclusion&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$Mutex&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #FF0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #5F9EA0; font-weight: bold;"&gt;New-Object&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #5F9EA0; font-style: italic;"&gt;-TypeName&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800000;"&gt;System.Threading.Mutex&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #5F9EA0; font-style: italic;"&gt;-ArgumentList&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$false&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$MutexName&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;
&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$Mutex&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;.WaitOne()

&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;#
&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;#&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt; Your program comes here&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;#
&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; 
&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;#&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt; Stop mutual exclusion&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$Mutex&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;.ReleaseMutex()
&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$Mutex&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #FF0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$null&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;
}
&lt;/SPAN&gt;&lt;SPAN style="color: #0000FF;"&gt;Catch&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; { 
&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;#&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt; Stop mutual exclusion&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$Mutex&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;.ReleaseMutex()
&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$Mutex&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #FF0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$null&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;
}&lt;/SPAN&gt;

&lt;/PRE&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first program that runs will get the mutual exclusion and will continue. The second program will wait untill the first program relases the mutual exclusion. This prevents both programs to run at the same time. That will assure that if P2 runs it fails and stop execution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The Try - Catch construction ensures that if an error is generated in your code, the mutex is still released before the program stops.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards, Robert&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: RvdNieuwendijk Added the Try - Catch explanation.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 04 Mar 2012 16:21:59 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Reserve-Space-on-the-Datastore/m-p/321784#M3291</guid>
      <dc:creator>RvdNieuwendijk</dc:creator>
      <dc:date>2012-03-04T16:21:59Z</dc:date>
    </item>
    <item>
      <title>Re: Reserve Space on the Datastore</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Reserve-Space-on-the-Datastore/m-p/321785#M3292</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Even if the created disks are thick provisioned, if both programs check the free space at the same time, they will both see enough free space and continue. By using the mutual exclusion they are not allowed to check for the free space at the same time. This will prevent the second program to see space that is already reserved by the first program as free space.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 04 Mar 2012 16:27:17 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Reserve-Space-on-the-Datastore/m-p/321785#M3292</guid>
      <dc:creator>RvdNieuwendijk</dc:creator>
      <dc:date>2012-03-04T16:27:17Z</dc:date>
    </item>
    <item>
      <title>Re: Reserve Space on the Datastore</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Reserve-Space-on-the-Datastore/m-p/321786#M3293</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the inputs.&lt;/P&gt;&lt;P&gt;My program is multithreaded in nature. It requires to do so. Otherwise the time taken to complete execution would be very large.&lt;/P&gt;&lt;P&gt;So mutexes I cannot use.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Nikunj&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Mar 2012 04:28:34 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Reserve-Space-on-the-Datastore/m-p/321786#M3293</guid>
      <dc:creator>NikunjB</dc:creator>
      <dc:date>2012-03-05T04:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: Reserve Space on the Datastore</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Reserve-Space-on-the-Datastore/m-p/321787#M3294</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could do your own bookkeeping and make a system in which programs reserve datastore space. In the most simple form you can make a .csv file with colums Datastore, Total Space, Space Reserved. Your program can read the .csv file. Search for a datastore with enough free space. Increase the reserved space for that datastore with the amount of space the program is going to use on the datastore. And write the new reserved space to the .csv file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To protect the .csv file from being used by two programs at the same time you still have to use the mutex. However in this case the mutex is only used for the bookkeeping and not during the creation of the VM's. So your programs can do more in parallel.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;An example of the .csv file:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;"Datastore","TotalSpace","SpaceReserved"&lt;BR /&gt;"datastore1","1000","950"&lt;BR /&gt;"datastore2","500","350"&lt;BR /&gt;"datastore3","1000","500"&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use the following PowerShell script to reserve space on a datastore in the .csv file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;PRE&gt;&lt;SPAN style="color: #0000FF;"&gt;param&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;([&lt;/SPAN&gt;&lt;SPAN style="color: #008080;"&gt;int&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;]&lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$SpaceNeeded&lt;/SPAN&gt;&lt;SPAN style="color: #FF0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;150&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;)

&lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$path&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #FF0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800000;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="color: #800000;"&gt;Datastores.csv&lt;/SPAN&gt;&lt;SPAN style="color: #800000;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;

&lt;/SPAN&gt;&lt;SPAN style="color: #0000FF;"&gt;Try&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; {
&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;#&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt; Get the mutex&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$MutexName&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #FF0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800000;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="color: #800000;"&gt;Global\Mutex&lt;/SPAN&gt;&lt;SPAN style="color: #800000;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;
&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$Mutex&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #FF0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #5F9EA0; font-weight: bold;"&gt;New-Object&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #5F9EA0; font-style: italic;"&gt;-TypeName&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800000;"&gt;System.Threading.Mutex&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #5F9EA0; font-style: italic;"&gt;-ArgumentList&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$false&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$MutexName&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;
&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$Mutex&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;.WaitOne() | &lt;/SPAN&gt;&lt;SPAN style="color: #5F9EA0; font-weight: bold;"&gt;Out-Null&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;

&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;#&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt; Find the first datastore with enough free space&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$DatastoreFound&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #FF0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$false&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;
&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$Datastores&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #FF0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #5F9EA0; font-weight: bold;"&gt;Import-Csv&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #5F9EA0; font-style: italic;"&gt;-Path&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$Path&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; | ForEach-Object {
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000FF;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; (&lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$_&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000FF;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; (&lt;/SPAN&gt;&lt;SPAN style="color: #FF0000;"&gt;-not&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$DatastoreFound&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #FF0000;"&gt;-and&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; (&lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$_&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;.TotalSpace &lt;/SPAN&gt;&lt;SPAN style="color: #FF0000;"&gt;-&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$_&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;.SpaceReserved &lt;/SPAN&gt;&lt;SPAN style="color: #FF0000;"&gt;-ge&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$SpaceNeeded&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;)) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$DatastoreFound&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #FF0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$_&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;.Datastore
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;/SPAN&gt;&lt;SPAN style="color: #008080;"&gt;int&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;] &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$_&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;.SpaceReserved &lt;/SPAN&gt;&lt;SPAN style="color: #FF0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; [&lt;/SPAN&gt;&lt;SPAN style="color: #008080;"&gt;int&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;] &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$_&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;.SpaceReserved &lt;/SPAN&gt;&lt;SPAN style="color: #FF0000;"&gt;+&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$SpaceNeeded&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$_&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
 }

&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;#&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt; Write the datastore reserved space information back to the .csv file&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000FF;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; (&lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$Datastores&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$Datastores&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; | &lt;/SPAN&gt;&lt;SPAN style="color: #5F9EA0; font-weight: bold;"&gt;Export-Csv&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #5F9EA0; font-style: italic;"&gt;-Path&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$Path&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #5F9EA0; font-style: italic;"&gt;-NoTypeInformation&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;
&amp;nbsp; }

&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;#&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt; Release the mutex&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$Mutex&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;.ReleaseMutex() | &lt;/SPAN&gt;&lt;SPAN style="color: #5F9EA0; font-weight: bold;"&gt;Out-Null&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;
&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$Mutex&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #FF0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$null&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;
}
&lt;/SPAN&gt;&lt;SPAN style="color: #0000FF;"&gt;Catch&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; {
&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;#&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt; Release the mutex when something went wrong&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$Mutex&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;.ReleaseMutex() | &lt;/SPAN&gt;&lt;SPAN style="color: #5F9EA0; font-weight: bold;"&gt;Out-Null&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;
&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$Mutex&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #FF0000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$null&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;
}

&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;#&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt; Return the name of the first datastore found with enough free space&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;
#&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt; Return $false if no datastore found&lt;/SPAN&gt;&lt;SPAN style="color: #008000;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;$DatastoreFound&lt;/SPAN&gt;

&lt;/PRE&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Mar 2012 08:47:14 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Reserve-Space-on-the-Datastore/m-p/321787#M3294</guid>
      <dc:creator>RvdNieuwendijk</dc:creator>
      <dc:date>2012-03-05T08:47:14Z</dc:date>
    </item>
  </channel>
</rss>

