...hopefully some useful VMware related stuff

Disconnect Virtual CD Drives - CD Remover

28/10/2009 11:55

The following script, sets the CD Drives of your virtual machines to the Client Device option.

It firstly lists machines with CD drives connected then gives you the option to remove or not remove for each one.

Download here

- - -

# Dans CD Remover
# cdremover.ps1
# 20091028
# Version 1.0
# https://www.a2-alpha.co.uk

# Sets up VI snapins for powershell
Add-PSsnapin VMware.VimAutomation.Core
Initialize-VIToolkitEnvironment.ps1

# Starts connection to a VC Server
$vcserver = "YOUR VCENTER SERVER"
connect-VIServer $vcserver
clear

# Title for page
""
"********************"
"* Dan's CD Remover *"
"*  a2-alpha.co.uk  *"
"********************"
""
#SELECTS ALL VIRTUAL MACHINES WHICH HAVE A CD DRIVE CONNECTED
$cdvms = Get-Vm | Where-Object {(((Get-CDDrive -VM $_ | Where-Object { (($_.ConnectionState.Connected -eq $True) -or ($_.ConnectionState.StartConnected -eq $True))} ) -ne $Null))}

#TESTS TO SEE IF ANY VMS ACTUALLY DO HAVE THEM CONNECTED
if($cdvms)
{

#FIRST LISTS THE VMS WITH DRIVES CONNECTED
""
"These Virtual Machines have CD Drives Connected"
""
$cdvms

#RUNS THROUGH EACH MACHINE AND ASKS IF YOU WANT TO MAKE CHANGES
foreach($cdvm in $cdvms)
{
""
"The Virtual Machine $cdvm has a CD Drive attached with the following settings:"
""
$cd = get-cddrive $cdvm
$cd
""
"Press Enter below to remove connections and set to Client device."
""

#ACTUALLY PERFORMS THE CHANGE HERE
set-cddrive -cd $cd -NoMedia -CONFIRM

""
}
}
#IF NO CD DRIVES CONNECTED RETURNS THE FOLLOWING
else
{
""
"There are no Virtual Machines with CD Drives connected"
""
}
 

Search site