2

I'm trying to find a way with PowerCLI to get a list of ISO's that are mounted in VM's and change the device type to "client device." Originally I thought that using the get-datastore would work to find the ISO's, however I was struggling to find ISO's, and ran into this line of code while doing some searching:

(Get-VM | Get-View | Where {$_.Runtime.ToolsInstallerMounted}) | % {$_.Name}

I tried this, however I didn't get a list of ISO's mounted. Was wondering if anyone here might know how to get a list of ISO's mounted on VM's and change the device type to client through scripting.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Valrok
  • 1,514
  • 7
  • 30
  • 49

1 Answers1

4

Try this, remove WhatIf to remove the ISO:

Get-VM | 
Get-CDDRive | 
Where-Object {$_.IsoPath} | 
Set-CDDrive -NoMedia -Confirm:$false -WhatIf
Shay Levy
  • 121,444
  • 32
  • 184
  • 206
  • I tested with the -whatif, but had a question for you Shay: is this only removing all the mounted ISO's in any VM's that I have or is this also switching the device type on VM's to client Device? With whatif it doesn't specify if it is also making the device type to client. – Valrok Jul 16 '12 at 17:07
  • @Julian The code finds all mounted ISO files (in all VMS) and sets the device type to 'client device' (no media). – Shay Levy Jul 16 '12 at 17:59
  • Thanks Shay! One last question, if I just want to search for a specific ISO what would I do to alter the filter? (let's assume the name of this ISO is"NAME.iso". I'm trying the following however when I do this it isn't returning any results: – Valrok Jul 16 '12 at 20:58
  • Get-VM | Get-CDDrive | Where-Object {$_.name -like "NAME.iso"} | Set-CDDrive -NoMedia -Confirm:$false -whatif – Valrok Jul 16 '12 at 21:02
  • 1
    Replace $_.Name with $_.IsoPath and try again – Shay Levy Jul 16 '12 at 21:03