1 Reply Latest reply on Dec 20, 2010 10:50 PM by LucD

    script to create folder on datastore please

    Ross Walter Novice

      hi all!

       

      I'm having difficulties in writing some powercli script to create a folder on a datastore... we've got a mixture of ESX 3.5, 4.0 and 4.1 hosts, using NFS mounted datastores.

       

      For some work I am doing, I need to:

       

      1) create a folder on a datastore (checking that the folder doesn't already exist),

      2) change directory to the folder

      3) and check to see if a particular file exists in that folder.

       

      The problem is that the context of my current location makes the code not work; the get-location method returns "C:\temp\ESX", being the folder that I'm running the test script from. I try using set-location with various parameters to try to change the location to a particular datastore, but it doesn't seem to work- get-location still returns "C:\temp\ESX".

       

      I believe the code for step 3) above is ok, but I can't get any code to work for 1) and 2).

       

      can someone please help?!

       

      thanks,

       

      Ross.

        • 1. Re: script to create folder on datastore please
          LucD Guru
          vExpertUser ModeratorsCommunity Warriors

          You have to use the vimdatastore provider to access your datastores.

          This is documented in the vSphere PowerCLI Administration Guide, which is installed on the PC where you installled PowerCLI.

           

          You can use the 'normal' cmdlets to navigate, test and create folders.

          For example:

           

          cd vmstore:

          ls                                           # Will show the top level

          cd MyDatastore\MyFolder     # Navigate with the 'cd' alias

          test-path MyOtherFolder       # Check for the existance of a folder or file

          mkdir test                               # Create a folder

           

          I hope this helps

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz