Hello,
I have the below simple code, however it's not producing what I would need to it produce. Any help would be appreciated. We have a handful of guests that don't have a CD/DVD Drive configured (meaning it's missing). What I would like to find is guests that don't have a CD/DVD drive, take that output and export it to csv.
Here is the simple code I have. It's get's only VM's that have a CD/DVD but skips the ones that don't
Get-VM | get-CDDrive |Export-Csv c:\scripts\cd.csv -NoTypeInformation
ESXi 4.1U2
vCenter 4.1 U2
Sorry for being late
To export only the VMs that do not have a CD/DVD, you could do
Get-VM | where {!(Get-CDDrive -VM $_)} | Select Name | Export-Csv c:\scripts\cd.csv -NoTypeInformation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Since Luc did not respond yet, you may try something like:
get-vm | format-table -wrap -autosize -property Name,CDDrives
found at http://waynes-world-it.blogspot.com/2009/08/vmware-vsphere-powercli-commands.html
André
Sorry for being late
To export only the VMs that do not have a CD/DVD, you could do
Get-VM | where {!(Get-CDDrive -VM $_)} | Select Name | Export-Csv c:\scripts\cd.csv -NoTypeInformation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That works, but can you explain your logic for us non PowerCLI people
What does the ! do/mean in the code that you are using?
{!(Get-CDDrive -VM $_)}
If I understand this correctly,
where {!(Get-CDDrive -VM $_)}
filters the result of Get-VM by running "Get-CDDrive" for each VM "-VM $_" and only returning those which don't "!" return a result.
André
That is correct, the '!' stands for NOT.
When the Get-CdDrive returns nothing, no CD/DVD drives, it will result in $null (which is converted to $False) being the result of the condition.
But since we want the inverse, we negate the result and '! $False' becomes $True.
So only the VM objects where there is no CD/DVD attached will pass through the Where-clause.
And the $_ represents the VM object that was passed through the pipeline to the Where-clause.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It does make sense. Thank you again! I guess my tab is already adding up for vBeers that I owe you at VMworld 2012
I'll book a couple of extra days in SF
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference