Hi Guys,
Need help pulling out more info from this script, the model of the esx hosts and filter powerstate of vm = on. This is what i have currently.
Connect-VIServer xxxxx
$date = Get-Date -format M-d-yyyy
Import-Csv C:\test\vmlisttest.csv -UseCulture | %{
Get-VM -Name $_.Name |
Select Name,
@{N='Datacenter';E={Get-Datacenter -VM $_ | Select -ExpandProperty Name}},
@{N='Cluster';E={Get-Cluster -VM $_ | Select -ExpandProperty Name}},
Host,NumCpu, MemoryGB,
ProvisionedSpaceGB,Powerstate
@{N='Path';E={
$current = Get-View $_.ExtensionData.Parent
$path = $_.Name
do {
$parent = $current
if($parent.Name -ne "vm"){$path = $parent.Name + "\" + $path}
$current = Get-View $current.Parent
} while ($current.Parent -ne $null)
[string]::Join('\',($path.Split('\')[0..($path.Split('\').Count-2)]))
}},
FolderId
} | Export-Csv “C:\test\test-vcenter-test-vmpath-$date.csv” -NoTypeInformation -UseCulture
sample output
Name | Datacenter | Cluster | Model | Host | NumCpu | MemoryGB | ProvisionedSpaceGB | Path | FolderId |
testvm | US | server | BL460c | esxdev-02.mak.esportz.com | 1 | 2 | 21.00084689 | US\Server\ | Folder-group-v4603 |
Cheers,
get-vm | where-object {$_.PowerState -eq "PoweredOn"} | Select Name, @{N='Model'; E={ (Get-VMHost -Name $_.Host).Model }}
has the basics of what you want to do I think.
So in your code add the where-object {$_.PowerState -eq "PoweredOn"} after Get-VM -Name $_.Name | to work on only the powered on VMs.
Then add @{N='Model'; E={ (Get-VMHost -Name $_.Host).Model }}, after @{N='Cluster';E={Get-Cluster -VM $_ | Select -ExpandProperty Name}},
get-vm | where-object {$_.PowerState -eq "PoweredOn"} | Select Name, @{N='Model'; E={ (Get-VMHost -Name $_.Host).Model }}
has the basics of what you want to do I think.
So in your code add the where-object {$_.PowerState -eq "PoweredOn"} after Get-VM -Name $_.Name | to work on only the powered on VMs.
Then add @{N='Model'; E={ (Get-VMHost -Name $_.Host).Model }}, after @{N='Cluster';E={Get-Cluster -VM $_ | Select -ExpandProperty Name}},
Hi Craig,
I tried to run this one liner and it works. was able to pull out the VM and the host model associated with it.
get-vm | where-object {$_.PowerState -eq "PoweredOn"} | Select Name, @{N='Model'; E={ (Get-VMHost -Name $_.Host).Model }}
when I incorporate the script you gave me the below is the output I get a bunch of datas.
PowerState | Version | Description | Notes | Guest | NumCpu | MemoryMB | MemoryGB | HardDisks | NetworkAdapters | UsbDevices | CDDrives | FloppyDrives | Host | HostId | VMHostId | VMHost | VApp | FolderId | Folder | ResourcePoolId | ResourcePool | PersistentId | UsedSpaceGB | ProvisionedSpaceGB | DatastoreIdList | HARestartPriority | HAIsolationResponse | DrsAutomationLevel | VMSwapfilePolicy | VMResourceConfiguration | GuestId | Name | CustomFields | ExtensionData | Id | Uid | Client |
This is how my script looks like now per your recommendation.
Connect-VIServer
$date = Get-Date -format M-d-yyyy
Import-Csv C:\test\vmlisttest.csv -UseCulture | %{
Get-VM -Name $_.Name | where-object {$_.PowerState -eq "PoweredOn"}
Select Name,
@{N='Datacenter';E={Get-Datacenter -VM $_ | Select -ExpandProperty Name}},
@{N='Model'; E={ (Get-VMHost -Name $_.Host).Model }},
@{N='Cluster';E={Get-Cluster -VM $_ | Select -ExpandProperty Name}},
Host,NumCpu, MemoryGB,
ProvisionedSpaceGB,Powerstate,
@{N='Path';E={
$current = Get-View $_.ExtensionData.Parent
$path = $_.Name
do {
$parent = $current
if($parent.Name -ne "vm"){$path = $parent.Name + "\" + $path}
$current = Get-View $current.Parent
} while ($current.Parent -ne $null)
[string]::Join('\',($path.Split('\')[0..($path.Split('\').Count-2)]))
}},
FolderId
} | Export-Csv “C:\test\test-vcenter-test-vmpath-$date.csv” -NoTypeInformation -UseCulture
Any Ideas?
Looks like I get it to worked already. I removed the where-object {$_.PowerState -eq "PoweredOn"} and it worked. If you have ideas why its causing to get all datas instead of the one defined please let me know. Thanks again.
here's how the script look like now.
Connect-VIServer
$date = Get-Date -format M-d-yyyy
Import-Csv C:\test\vmlisttest.csv -UseCulture | %{
Get-VM -Name $_.Name |
Select Name,
@{N='Datacenter';E={Get-Datacenter -VM $_ | Select -ExpandProperty Name}},
@{N='Cluster';E={Get-Cluster -VM $_ | Select -ExpandProperty Name}},
Host,NumCpu, MemoryGB,
ProvisionedSpaceGB,Powerstate,
@{N='Path';E={
$current = Get-View $_.ExtensionData.Parent
$path = $_.Name
do {
$parent = $current
if($parent.Name -ne "vm"){$path = $parent.Name + "\" + $path}
$current = Get-View $current.Parent
} while ($current.Parent -ne $null)
[string]::Join('\',($path.Split('\')[0..($path.Split('\').Count-2)]))
}},
FolderId,
@{N='Manufacturer'; E={ (Get-VMHost -Name $_.Host).Manufacturer }},
@{N='Model'; E={ (Get-VMHost -Name $_.Host).Model }},
@{N='ProcessorType'; E={ (Get-VMHost -Name $_.Host).ProcessorType }}
} #| Export-Csv “C:\test\test-vcenter-test-vmpath-$date.csv” -NoTypeInformation -UseCulture
There doesn't seem to be a pipeline symbol ('|') at the end of the line with the Where-clause
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
o wow thanks LucD!