PowerCLI

  • 1.  Missing something mapping all VMs to an ISO

    Posted Feb 17, 2025 04:27 PM

    My one-liner:

    Get-Cluster "clustername" | Get-VM | ForEach {Set-CDDrive -VM $_ -IsoPath "[OverlyLongDSName] ISO/updates.iso" -Connected $true}
    Complains that:
    Line |
       2 |  Get-Cluster "clustername" | Get-VM | ForEach {Set-CDDrive -VM $_ -IsoPath …
         |                                                        ~~~
         | A parameter cannot be found that matches parameter name 'VM'.
    I feel like this is something simple that I'm missing, but what is it?


  • 2.  RE: Missing something mapping all VMs to an ISO
    Best Answer

    Posted Feb 18, 2025 12:25 AM

    You will have to a Get-CDDrive first

    Get-Cluster "clustername" | Get-VM | 
    ForEach-Object -Process {
        Get-CDDrive -VM $_ |
        Set-CDDrive -IsoPath "[OverlyLongDSName] ISO/updates.iso" -Connected $true
    }


    ------------------------------


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


    ------------------------------



  • 3.  RE: Missing something mapping all VMs to an ISO

    Posted Feb 18, 2025 10:59 AM
    Edited by rblake Feb 18, 2025 10:59 AM

    Works great!  As a side note for anyone else seeing this, I added a check to only hit the Windows boxes because the Linux ones don't need / can't use it, and on the reverse, when disconnecting them all, wants you to answer a question before proceeding.  (And for my needs, I don't need to do that or work around it.)

    Get-Cluster "clustername" | Get-VM | Where {$_.Guest -match 'windows'} | ForEach {Get-CDDrive -VM $_ | Set-CDDrive -IsoPath "[OverlyLongDatastorePath] ISO/updates.iso" -Connected $true -confirm:$false} 
    Get-Cluster "clustername" | Get-VM | Where {$_.Guest -match 'windows'} | ForEach {Get-CDDrive -VM $_ | Set-CDDrive -NoMedia -Connected $false -confirm:$false }