Hi All and
LucD The Champ !!
I am looking for a power-cli script in order to check VM-tools status of all VMs in the multi cluster environment. Could you please help me out on this. It would be really appreciated.
Thanks. in advance.
Regards
Nauman
Try like this
$report = @()
foreach($cluster in Get-Cluster){
foreach($rp in Get-ResourcePool -Location $cluster){
foreach($vm in (Get-VM -Location $rp)){
$report += Get-HardDisk -VM $vm |
Select @{N='Cluster';E={$cluster.Name}},
@{N='ResourcePool';E={$rp.Name}},
@{N='VM';E={$vm.Name}},
@{N="Tools Status";E={$vm.ExtensionData.Guest.ToolsStatus}},
@{N='HD';E={$_.Name}},
@{N='Datastore';E={($_.Filename.Split(']')[0]).TrimStart('[')}},
@{N='Filename';E={($_.Filename.Split(' ')[1]).Split('/')[0]}},
@{N='VMDK Path';E={$_.Filename}},
@{N='Format';E={$_.StorageFormat}},
@{N='Type';E={$_.DiskType}},
@{N='CapacityGB';E={$_.CapacityGB}}
}
}
}
$report | Export-Csv C:\temp\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Something like this ?
Get-VM | Select Name,
@{N="Tools Installed";E={$_.Guest.ToolsVersion -ne ""}},
@{N="Tools Status";E={$_.ExtensionData.Guest.ToolsStatus}},
@{N="Tools version";E={if($_.Guest.ToolsVersion -ne ""){$_.Guest.ToolsVersion}}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Do you want to do anything with the information? For instance, do you want to know which ones are NOT current? do you want to initiate an upgrade? Or are you looking to see if tools are running?
Thanks LucD
this script doesn't contains the resource pools. I want to identify VM tools as per resource pool basis. Basically, i want to run the below script correctly but couldn't run properly. I want to include VM tools correctly in this script as well. I just need to check the current VM tool status that it.
connect-viserver -Server .................
$report = @()
foreach($cluster in Get-Cluster){
foreach($rp in Get-ResourcePool -Location $cluster){
foreach($vm in (Get-VM -Location $rp)){
$report += Get-HardDisk -VM $vm |
Select @{N='Cluster';E={$cluster.Name}},
@{N='ResourcePool';E={$rp.Name}},
@{N='VM';E={$vm.Name}},
@{N='HD';E={$_.Name}},
@{N='Datastore';E={($_.Filename.Split(']')[0]).TrimStart('[')}},
@{N='Filename';E={($_.Filename.Split(' ')[1]).Split('/')[0]}},
@{N='VMDK Path';E={$_.Filename}},
@{N='Format';E={$_.StorageFormat}},
@{N='Type';E={$_.DiskType}},
@{N='CapacityGB';E={$_.CapacityGB}}
@{N='VMware Tools';E={$_.Guest.ToolsStatus}}
}
$report | Export-Csv C:\temp\report.csv -NoTypeInformation -UseCulture
}
}
Want to see VM Tools status only as per resource pool basis
LucD
Can i use the script this way ?
connect-viserver -Server .....................
$report = @()
foreach($cluster in Get-Cluster){
foreach($rp in Get-ResourcePool -Location $cluster){
foreach($vm in (Get-VM -Location $rp)){
$report += Get-HardDisk -VM $vm |
Select @{N='Cluster';E={$cluster.Name}},
@{N='ResourcePool';E={$rp.Name}},
@{N='VM';E={$vm.Name}},
@{N='HD';E={$_.Name}},
@{N='Datastore';E={($_.Filename.Split(']')[0]).TrimStart('[')}},
@{N='Filename';E={($_.Filename.Split(' ')[1]).Split('/')[0]}},
@{N='VMDK Path';E={$_.Filename}},
@{N='Format';E={$_.StorageFormat}},
@{N='Type';E={$_.DiskType}},
@{N='CapacityGB';E={$_.CapacityGB}}
@{N="Tools Installed";E={$_.Guest.ToolsVersion -ne ""}},
@{N="Tools Status";E={$_.ExtensionData.Guest.ToolsStatus}},
@{N="Tools version";E={if($_.Guest.ToolsVersion -ne ""){$_.Guest.ToolsVersion}}}
}
$report | Export-Csv C:\temp\report.csv -NoTypeInformation -UseCulture
}
}
Its seems not correct. If you could correct it.
This will create one report, or do you want a separate report per resourcepool ?
Not sure I get what you mean with the "VM Tools status per resourcepool".
$report = @()
foreach($cluster in Get-Cluster){
foreach($rp in Get-ResourcePool -Location $cluster){
foreach($vm in (Get-VM -Location $rp)){
$report += Get-HardDisk -VM $vm |
Select @{N='Cluster';E={$cluster.Name}},
@{N='ResourcePool';E={$rp.Name}},
@{N='VM';E={$vm.Name}},
@{N="Tools Status";E={$vm.ExtensionData.Guest.ToolsStatus}},
@{N='HD';E={$_.Name}},
@{N='Datastore';E={($_.Filename.Split(']')[0]).TrimStart('[')}},
@{N='Filename';E={($_.Filename.Split(' ')[1]).Split('/')[0]}},
@{N='VMDK Path';E={$_.Filename}},
@{N='Format';E={$_.StorageFormat}},
@{N='Type';E={$_.DiskType}},
@{N='CapacityGB';E={$_.CapacityGB}}
@{N='VMware Tools';E={$_.Guest.ToolsStatus}}
}
}
}
$report | Export-Csv C:\temp\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD
No i want a csv file with one resource-pools column and all VM tools information like VM tool status, installed, version etc on other columns. thats it. Please ignore my below code.
like each resource pools shows the VM with VM tools information in one single csv file.
Thanks in Advance.
But you would still need a row per VM ?
Otherwise, how would you indicate the VMware Tools status and version ?
Perhaps a sample layout of the desired report would be handy.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, Correct. You are right. Basically, we are looking to identify as per resource pool basis like which resource pools has vmtools installed etc. You can include that row as well.
Should this line
@{N='VMware Tools';E={$_.Guest.ToolsStatus}}
Not read
@{N='VMware Tools';E={$vm.Guest.ToolsStatus}}
Thanks Calvin but it doesn't show the VM tool columns in CSV file.
@{N='VMware Tools';E={$vm.ExtensionData.Guest.ToolsStatus}}
LucD Please help me out on this. Thanks.
Hi LucD
I have managed to create the below script but still unable to get whole csv report. There must be something missing. Also can i add more VM tool information in this script like VM status etc
$report = @()
foreach($cluster in Get-Cluster){
foreach($rp in Get-ResourcePool -Location $cluster){
foreach($vm in (Get-VM -Location $rp)){
$report += Get-HardDisk -VM $vm |
Select @{N='Cluster';E={$cluster.Name}},
@{N='ResourcePool';E={$rp.Name}},
@{N='VM';E={$vm.Name}},
@{N='HD';E={$_.Name}},
@{N='Datastore';E={($_.Filename.Split(']')[0]).TrimStart('[')}},
@{N='Filename';E={($_.Filename.Split(' ')[1]).Split('/')[0]}},
@{N='VMDK Path';E={$_.Filename}},
@{N='Format';E={$_.StorageFormat}},
@{N='Type';E={$_.DiskType}},
@{N='CapacityGB';E={$_.CapacityGB}},
@{N="Tools Installed";E={$vm.Guest.ToolsVersion -ne ""}},
@{N='VMware Tools';E={$vm.ExtensionData.Guest.ToolsStatus}}
}
$report | Export-Csv C:\temp\report.csv -NoTypeInformation -UseCulture
}
}
Try like this
$report = @()
foreach($cluster in Get-Cluster){
foreach($rp in Get-ResourcePool -Location $cluster){
foreach($vm in (Get-VM -Location $rp)){
$report += Get-HardDisk -VM $vm |
Select @{N='Cluster';E={$cluster.Name}},
@{N='ResourcePool';E={$rp.Name}},
@{N='VM';E={$vm.Name}},
@{N="Tools Status";E={$vm.ExtensionData.Guest.ToolsStatus}},
@{N='HD';E={$_.Name}},
@{N='Datastore';E={($_.Filename.Split(']')[0]).TrimStart('[')}},
@{N='Filename';E={($_.Filename.Split(' ')[1]).Split('/')[0]}},
@{N='VMDK Path';E={$_.Filename}},
@{N='Format';E={$_.StorageFormat}},
@{N='Type';E={$_.DiskType}},
@{N='CapacityGB';E={$_.CapacityGB}}
}
}
}
$report | Export-Csv C:\temp\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD Thanks for this code but it stops after 40KB size
i have modified it like below and its working fine. Can i add more VM Tools info like Tool verions etc or not ?
$report = @()
foreach($cluster in Get-Cluster){
foreach($rp in Get-ResourcePool -Location $cluster){
foreach($vm in (Get-VM -Location $rp)){
$report += Get-HardDisk -VM $vm |
Select @{N='Cluster';E={$cluster.Name}},
@{N='ResourcePool';E={$rp.Name}},
@{N='VM';E={$vm.Name}},
@{N='HD';E={$_.Name}},
@{N='Datastore';E={($_.Filename.Split(']')[0]).TrimStart('[')}},
@{N='Filename';E={($_.Filename.Split(' ')[1]).Split('/')[0]}},
@{N='VMDK Path';E={$_.Filename}},
@{N='Format';E={$_.StorageFormat}},
@{N='Type';E={$_.DiskType}},
@{N="Tools Status";E={$vm.ExtensionData.Guest.ToolsStatus}},
@{N='CapacityGB';E={$_.CapacityGB}}
}
$report | Export-Csv C:\temp\report.csv -NoTypeInformation -UseCulture
}
}
Stops after 40KB, that is strange, never saw that before.
Since you placed the Export-Csv inside the ForEach loop, the CSV file will get overwritten several times (depending on how many VMs you have).
You can add addition VMware Tools properties, see the addition calculated properties I gave earlier.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sorry its my mistake srcipt was right it takes 5 to 10 minutes from 40KB to onwards.
Many thanks.