Hello, Can you suggest a script to get in csv file list of virtual machine, with cpu,memory and disk allocate and in which host they are. Thanks
You mean something like this?
Get-VM |
Select Name,@{N='VMHost';E={$_.VMHost.Name}},
NumCpu,MemoryGB,UsedSpaceGB |
Export-Csv report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
A simple straight one liner would be like this.
Connect-VIServer 'YourvCenterName'
Get-VM | Export-Csv -path “c:\reports\vminventory.csv” –NoTypeInformation
This will export all information regarding VM into CSV file and you can use filter to exclude information you dont want.
If you are looking for specific information you mentioned, use below command :
Connect-VIServer 'YourvCenterName'
Get-VM | select Name, NumCpu, MemoryGB, HardDisks, Host | Export-Csv -path “c:\reports\vminventory.csv” -NoTypeInformation
Afaik there are no HardDisks nor Host properties anymore on a VirtualMachine object since PowerCLI 5.0.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks a lot for explanation, very useful for newbie like me.
Thanks LucD for correction as always
Yes I checked these properties are depreciated, and its working with :
Get-VM | select Name, NumCpu, MemoryGB, ProvisionedSpaceGB, UsedSpaceGB, VMHost | Export-Csv -path “c:\reports\vminventory.csv” -NoTypeInformation
Whereas :
ProvisionedSpaceGB = Hard disk space allocated as VMDK.
UsedSpaceGB = Actual Space used inside VMDK
Thanks LucD and vijayrana968 for help.
Hello LucD,
I didn't want to open a new threat as is the same topic.
I would like to get the same output with some more information, a VM with Numcpu, memoryGB, a custom attribute + the vmdk attached to the VM and their corresponding datastore.
I have code for the 1st part, but I do not know how can I add the get-harddisk | select-object filename, capacityGB to the $report and concatenate the result,
Any hint would be appreciated, thank you.
Get-VM -name "*name*" | ForEach-Object {
$VM = $_
$VM | Get-Annotation -CustomAttribute "Roles"|`
ForEach-Object {
$Report = "" | Select-Object VM,Value,NumCpu,MemoryGB
$Report.VM = $VM.Name
$Report.NumCpu = $VM.NumCpu
$Report.MemoryGB = $VM.MemoryGB
$Report.Value = $_.Value
$Report
}
}
Running through all the harddisks is another loop.
How do you intend to display that harddisk information in the output?
If you envisage a line per harddisk, there will be a lot of duplicated information (if a VM has more than 1 harddisk).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes, that's the idea, it does not bother me to have for example 5 lines showing the same vm name with 5 vmdk files.
You could do something like this
Get-VM -Name "*name*" -PipelineVariable vm |
ForEach-Object {
Get-HardDisk -VM $vm |
ForEach-Object -Process {
New-Object -TypeName PSObject -Property ([ordered]@{
VM = $vm.Name
Roles = (Get-Annotation -Entity $vm -CustomAttribute "Roles").Value
NumCpu = $vm.NumCpu
MemoryGB = $vm.MemoryGB
HDName = $_.Name
HDFilename = $_.Filename
HDSizeGB = $_.CapacityGB
})
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you LucD, that worked for me^^