VMware Cloud Community
ben1985
Contributor
Contributor
Jump to solution

Modify output of Get-CDDrive

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?

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this

get-vm | get-cddrive | select @{N='ISO';E={$_.IsoPath.Split(' /')[-1]}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
ben1985
Contributor
Contributor
Jump to solution

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.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
ben1985
Contributor
Contributor
Jump to solution

Is it possible to have it without @{ISO=} in the output?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
ben1985
Contributor
Contributor
Jump to solution

Yes that's exactly what I wanted. Thanks!

Reply
0 Kudos