I have a simple command which gets the IsoPath of a selection of VM folders:
get-vm -location "testfolder" | get-cddrive | select isopath
This outputs the entire ISO location however I just want to display the ISO name (e.g. test.iso). Is there an easy way to do this?
Like this you mean ?
$vms | Select Name,
@{N='ISO';E={(Get-CDDrive -VM $_ | Select -ExpandProperty IsoPath).Split(' /')[-1]}},
@{N='TYPE';E={Get-NetworkAdapter -VM $_ | Select -ExpandProperty Type}},
@{N='NICNAME';E={Get-NetworkAdapter -VM $_ | Select -ExpandProperty NetworkName}} |
format-table
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try like this
get-vm | get-cddrive | select @{N='ISO';E={$_.IsoPath.Split(' /')[-1]}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Is there a way that I can incorporation this into my current code?
$vms | Select Name,
@{N='ISO';E={Get-CDDrive -VM $_ | Select -ExpandProperty IsoPath}},
@{N='TYPE';E={Get-NetworkAdapter -VM $_ | Select -ExpandProperty Type}},
@{N='NICNAME';E={Get-NetworkAdapter -VM $_ | Select -ExpandProperty NetworkName}} | format-table | Out-Default
I attempted combining it in but then I can't get it to output the ISO at all.
You have to use a calculated property, like this
$vms | Select Name,
@{N='ISO';E={Get-CDDrive -VM $_ | Select @{N='ISO';E={$_.IsoPath.Split(' /')[-1]}}}},
@{N='TYPE';E={Get-NetworkAdapter -VM $_ | Select -ExpandProperty Type}},
@{N='NICNAME';E={Get-NetworkAdapter -VM $_ | Select -ExpandProperty NetworkName}} |
format-table
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Is it possible to have it without @{ISO=} in the output?
Like this you mean ?
$vms | Select Name,
@{N='ISO';E={(Get-CDDrive -VM $_ | Select -ExpandProperty IsoPath).Split(' /')[-1]}},
@{N='TYPE';E={Get-NetworkAdapter -VM $_ | Select -ExpandProperty Type}},
@{N='NICNAME';E={Get-NetworkAdapter -VM $_ | Select -ExpandProperty NetworkName}} |
format-table
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes that's exactly what I wanted. Thanks!
