Skip to content

Instantly share code, notes, and snippets.

@sneal
Created July 14, 2023 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sneal/5a60f8b2045024a1e6fea7c11b458d3e to your computer and use it in GitHub Desktop.
Save sneal/5a60f8b2045024a1e6fea7c11b458d3e to your computer and use it in GitHub Desktop.

This PowerCLI snippet can be used to find all the BOSH VMs connected to a specific datastore and then disconnect the CD-ROM to avoid vMotion or SDRS errors.

  1. Open a PowerCLI session and login to the appropriate vCenter using the Connect-VIServer command.
  2. Copy the below eject-iso.ps1 snippet locally
  3. Change the datastore name, from dsname to whatever your datastore name is.
  4. Execute the script

The final output table will contain all the VMs processed and list out the updated ISOPaths which should be empty at this point.

NOTE The script only modifies BOSH VMs, i.e. those with mounted env.iso files, however the output will display all VMs on the specified datastore and any other non-BOSH ISOs mounted.

# Replace the below 'dsname' with the datastore you want to evacuate
$dsid=(Get-Datastore -Name 'dsname' | Select-Object -ExpandProperty Id);
Get-VM | Where-Object {$_.DatastoreIdList -eq "$dsid"} | Get-CDDrive | Where-Object {$_.IsoPath -like '*/env.iso'} | Set-CDDrive -NoMedia -Confirm:$False
Get-VM | Where-Object {$_.DatastoreIdList -eq "$dsid"} | Get-CDDrive | Format-Table Parent, ISOPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment