I am wondering if you can look at this script and tell me what I am doing wrong. Basically I am trying to write a simple script that asks for a minimum free space and searches all data stores and reports back…
Connect-VIServer -Server "vcenter1" -Credential(Get-Credential)
$a = Read-Host "Enter minimum datastore size in GB's to search all stores by: "
Get-vmhost | Get-Datastore | ? { $_.FreespaceMB -lt ( "$a"GB/1MB) }
I am new to powershell and really trying to learn it because I definately see the benefit.
Thanks in advance!
eric
Try it like this
$a = Read-Host "Enter minimum datastore size in GB's to search all stores by: " Get-vmhost | Get-Datastore | ? { $_.FreespaceMB -lt ( ([int]$a * 1KB)) }
The Read-Host cmdlet returns a string, use the explicit conversion to integer to do the calculation.
The FreespaceMB is in MB, so you only have to multiple the input (in GB) by 1024 (or 1KB) to get to MB
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try it like this
$a = Read-Host "Enter minimum datastore size in GB's to search all stores by: " Get-vmhost | Get-Datastore | ? { $_.FreespaceMB -lt ( ([int]$a * 1KB)) }
The Read-Host cmdlet returns a string, use the explicit conversion to integer to do the calculation.
The FreespaceMB is in MB, so you only have to multiple the input (in GB) by 1024 (or 1KB) to get to MB
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Works!
Thanks for your help, someday I will get this powershell thing.