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...
http://serverfault.com/questions/98220/setting-multiple-swapfile-datastores-on-a-host-question