Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to automate -vmswapdatastore location on my cluster and so far I managed to add single datastore that can be used. Problem is i can't figure out how to add multiple datastores that are allocated to swapfile datstores on my cluster.

here is my code:

connect-viserver vcenter

foreach ($vmhost in get-cluster "clustername" | get-vmhost)

{ Get-vmhost $vmhost | set-vmhost -vmswapfiledatastore "VS01" }

this works perfectly but I can't add more of them and if i try to add another one it just replaces the current one with new one. so how would i go about adding vs02 and vs03 to the datstores?

What is the trick to doing this?


share|improve this question
up vote 2 down vote accepted

rather than { Get-vmhost $vmhost | set-vmhost -vmswapfiledatastore "VS01" }, could you not use different data store names, to make it easier to script?

eg: { Get-vmhost $vmhost | set-vmhost -vmswapfiledatastore "VS-$vmhost" }

saves you having to bother counting how many machines are running, or which ones is using what datastore.

I'm probably completely off the mark and missed the point, but...

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.