VMware Cloud Community
Ross_Walter
Contributor
Contributor
Jump to solution

script to create folder on datastore please

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.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
1 Reply
LucD
Leadership
Leadership
Jump to solution

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos