Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 180923

Automating New-VM: Get-Datastore greater than X gb from csv-file.

$
0
0

Hey all,

 

I recently bought the awesome book VMware vSphere PowerCLI Reference: Automating vSphere Administration and have been working on a modified script of the VM mass deployment.

 

I know it's not the most pretty code but it's a work in progress.

 

I have a csv-file, MassVMs.txt, with a "HardDisk" column and a "Cluster" column.

I want the script to take a random host in cluster X (from the csv-file) where the minimum avaliable disk is 1.1 times harddisk Y (from the csv-file).

 

Import-Csv .\MassVMs.txt|

     Foreach-Object {
          Get-Datastore -VMHost (get-cluster $_.Cluster|get-vmhost|get-random)|Where {($_.FreeSpaceMB * 1mb) -gt (($_.HardDisk * 1gb) * 1.1 )}
     }

 

The random host in Cluster X-part works great, $_.Cluster retrieves the specified cluster from the file.

Howerver $_.HardDisk doesn't as it seems, the scrip runs without errors and outputs all datastores in the cluster. If I replace "$_.HardDisk" with e.g. 100 it works as it should.

 

My conclusion is that maybe some command breaks the "connection" to the file? Or that I'm simply doing completely wrong. Anyone got any pointers?


Viewing all articles
Browse latest Browse all 180923

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>