VMware Cloud Community
Butcha
Contributor
Contributor

How Do We Manage Files on the ESX local Filesystems Using Powershell & the VI Toolkit

Hello guys!!!

I've been able to find a wealth of information in this forum regarding the usage of the VI Toolkit, but there has been at least one aspect that remains elusive. What methods and properties do we invoke and\or use to manipulate files within the local filesystem on the ESX host itself? This info can be easily found regarding Microsoft hosts, as the WMI namespace includes a rich set of well documented properties and methods, however its been a pain finding this same set of info for ESX hosts. For example, If I wanted to simply push a file to every host in my farm........

0 Kudos
4 Replies
SCampbell1
Enthusiast
Enthusiast

Hi there,

There are some upload/download cmdlets created by Carter Shanklin of VMware at www.codeplex.com/vitoolkitextensions.

Basically ESX/ESXi upload/download are implemented using https get/put transactions so you can leave ssh disabled.

There are some useful configuration and logging URL's located under

You can also use the New-PSDrive to attach to Datastores and perform some file actions. This is explained in the Advanced Cmdlet/Datastore provider section

Butcha
Contributor
Contributor

Thanks so much for your help! You were absolutely correct, I was able to look it up in the 'advanced cmdlet usage' section of the guide and that helped quite a bit! I used the example right out of the guide to get a handle on this simple method :

#Get a datstore by its name and assign it to the $datastore variable.

$datastore = Get-Datastore Storage1

#Create a PowerShell drive ds:, based on $datastore. You can use the built-in New-PSDrive cmdlet.

New-PSDrive -Location $datastore -Name ds -PSProvider VimDatastore -Root '\'

I did, however, run into a couple of issues, one of which still puzzles me...........

#1 I had to insert a wildcard in front of 'Storage1' since the entire name of the local datastore is something like ':Storage1'.

This worked out just fine!

#2 The second line ran with no hitches, BUT when I switch to my newly created PS Drive, using 'cd ds:', I dont see any data or anything no matter if I use ls, dir, or get-childitem. Also, if I do 'cd /', it seems to do nothing. I guess my question is: once the PS Drive is created using the forementioned method, just where will the mountpoint be within the host's local filesystem? Also, is there a way to actually specify this?

0 Kudos
SCampbell1
Enthusiast
Enthusiast

With server:Storage1, you are connecting to the local VMFS datastore on that server, not the root filesystem of the ESX server.

When you build a fresh server, that datastore will be empty so that's why you're not seeing anything. You can verify this by using VIClient (connecting directly to the ESX/ESXi server using the root password if the server isn't part of a VC environment yet) to get the Datastore view, then open the Datastore browser, and create folders and upload files there. Then you'll start to see them from your PSDrive script

I will look at how you can get at the native ESX file system using psdrive. There may be a way, but will need to check the "real" SDK: may not be until tomorrow though. You can check my NAEPS script (http://communities.vmware.com/docs/DOC-8170) to see how to do uploads to the url, but it is non-trivial. There is a more generic upload capability in the VIToolkitExtensions I mentioned earlier. Your post also prompted me to post the NADUS (http://communities.vmware.com/docs/DOC-8381) script we're using to upload ISO's to a VMFS volume.

I am also not sure whether you can upload files with the PSDRIVE object. However, I believe you can copy from VMFS to VMFS partition.

Bottom line - I haven't tried to get at the native Linux file system yet. But I'm sure if we get the right URL on the transfer function we can get it to work.

0 Kudos
halr9000
Commander
Commander

I am also not sure whether you can upload files with the PSDRIVE object. However, I believe you can copy from VMFS to VMFS partition.

You cannot. The VimDatastore and VimInventory psproviders are merely read-only right now (and marked as experimental you'll notice if you read the release notes). But vmware has some neat stuff planned for the upcoming version.






Author of the upcoming book: Managing VMware Infrastructure with PowerShell

Co-Host, PowerScripting Podcast (http://powerscripting.net)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
0 Kudos