PowerCLI

 View Only
  • 1.  unmount cdrom from all vms in datastores and remount

    Posted Apr 07, 2015 01:12 AM

    I need to find out all vms in a datastore to what iso they are mapped to


    get-datastore lunname | Get-VM | Get-CDDrive | select @{N="VM";E="Parent"

    },IsoPath | where {$_.IsoPath -eq  "[lunname] ISO/isoname.iso"} | ft -auto

    then I need to unmount the iso, move the folder and remount these iso to the same vms

    whats best way to approach this?

    I can dismount the the iso in one line, move the folder

    but I will need to keep track of what vms needs to remount the iso to the new datastore path



  • 2.  RE: unmount cdrom from all vms in datastores and remount

    Posted Apr 07, 2015 07:49 AM

    Something like this ?

    You could export the content of $isoVMs to a CSV before you unmount the ISO, just to be on the safe side

    # Unmount ISO

    $vms = Get-Datastore lunname | Get-VM

    $isoVMs = $vms | Where {Get-CDDrive -VM $_ | where {$_.IsoPath -eq  "[lunname] ISO/isoname.iso"}}

    $isoVMs | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$false

    # ==> Do your stuff

    # Mount ISO

    $isoVMs | Set-CDDrive -IsoPath "[lunname] ISO/isoname.iso" -Connected -Confirm:$false



  • 3.  RE: unmount cdrom from all vms in datastores and remount

    Posted Apr 07, 2015 03:14 PM

    hi Lucd

    If I want to add this line

    get-datastore lunname | get-vm | move-vm -datastore destinationdatastore

    after the disconnection of all cdroms, do you think I need to add a sleep line in there or wait for all that to finish before svmotion?



  • 4.  RE: unmount cdrom from all vms in datastores and remount

    Posted Apr 07, 2015 03:48 PM

    If you run the Move-VM without the RunAsync switch, there is no need to wait.