<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>article NARMD (Not Another Removable Media Disconnector) in VMware PowerCLI Documents</title>
    <link>https://communities.vmware.com/t5/VMware-PowerCLI-Documents/NARMD-Not-Another-Removable-Media-Disconnector/ta-p/2779526</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;We are using this script to provide a slightly more user-friend CDROM and floppy disconnect environment. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can easily disconnect all CDROMS with &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="code"&gt;Get-VM | Get-CDROMDrive | Set-CDROMDrive -Connected $False -Confirm:$False&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However you have little control over the above process, and might disconnect things that are actually in use. This script presents a list of VM's whose CDROM(s) or Floppie(s) are connected now, or are set to connect at startup, then prompts the operator to continue. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the operator confirms the action, it will go ahead and disconnect all the CDROMs and Floppies and uncheck the Connect At Startup, but at least the operator knows what's happening. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want a log file you can invoke this as follows: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="code"&gt;.\removableDrives.ps1 | Tee-Object C:\Logs\removableDrives.log&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's a sample console session (up to the prompt) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN __default_attr="courier new" __jive_macro_name="font"&gt;
VM: Server1 (PoweredOff)
  CD/DVD Drive 1 Connected=True ConnectAtPowerUp=True
  Floppy Drive 1 Connected=False ConnectAtPowerUp=False
VM: Server2 (PoweredOff)
  CD/DVD Drive 1 Connected=True ConnectAtPowerUp=True
  Floppy Drive 1 Connected=True ConnectAtPowerUp=True
VM: Workstation3 (PoweredOff)
  CD/DVD Drive 1 Connected=True ConnectAtPowerUp=True
  Floppy Drive 1 Connected=False ConnectAtPowerUp=False
VM: DomainController1 (PoweredOn)
  CD/DVD Drive 1 Connected=True ConnectAtPowerUp=True
  Floppy Drive 1 Connected=False ConnectAtPowerUp=True
Do you want to disconnect all removable drives, and disable the connect
  at startup?  If you don't see any VMs everything is OK and you should
  select N here.  Type Y or N:
&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The script is here for full-text searching, and is also attached. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN __default_attr="courier new" __jive_macro_name="font"&gt;"removableDrives.ps1 Version 1.0a starting" 
connect-viserver ($env:computername + "." + $env:userdnsdomain) | out-null 


Get-Vm | Where-Object {
(((Get-CDDrive -VM $_ | Where-Object { (($_.ConnectionState.Connected -eq $True) -or ($_.ConnectionState.StartConnected -eq $True))} ) -ne $Null) `
-or `
((Get-FloppyDrive -VM $_ | Where-Object { (($_.ConnectionState.Connected -eq $True) -or ($_.ConnectionState.StartConnected -eq $True))} ) -ne $Null))
} | %{
"VM: " + $_.Name + " (" + $_.PowerState + ")"
Get-CDDrive -VM $_ | ForEach-Object { " " + $_.Name + " Connected=" + $_.ConnectionState.Connected + " ConnectAtPowerUp=" + $_.ConnectionState.StartConnected }
Get-FloppyDrive -VM $_ | ForEach-Object { " " + $_.Name + " Connected=" + $_.ConnectionState.Connected + " ConnectAtPowerUp=" + $_.ConnectionState.StartConnected }
}

if ("Y" -eq (Read-Host `
("Do you want to disconnect all removable drives, and disable the connect `n" + `
" at startup? If you don't see any VMs everything is OK and you should `n" + `
" select N here. Type Y or N"))) {
Get-Vm | Where-Object {
(((Get-CDDrive -VM $_ | Where-Object { (($_.ConnectionState.Connected -eq $True) -or ($_.ConnectionState.StartConnected -eq $True))} ) -ne $Null) `
-or `
((Get-FloppyDrive -VM $_ | Where-Object { (($_.ConnectionState.Connected -eq $True) -or ($_.ConnectionState.StartConnected -eq $True))} ) -ne $Null))
} | %{
"VM: " + $_.Name + " (" + $_.PowerState + ")"
Get-CDDrive -VM $_ | ForEach-Object { Set-CDDRIVE -CD $_ -StartConnected $False -Connected $False -Confirm:$False | %{ " Changed " + $_.Name} }
Get-FloppyDrive -VM $_ | ForEach-Object { Set-FloppyDRIVE -Floppy $_ -StartConnected $False -Connected $False -Confirm:$False | %{ " Changed " + $_.Name} }
}
} 

"removableDrives.ps1 finished."&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 21 Oct 2008 16:58:25 GMT</pubDate>
    <dc:creator>SCampbell1</dc:creator>
    <dc:date>2008-10-21T16:58:25Z</dc:date>
    <item>
      <title>NARMD (Not Another Removable Media Disconnector)</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Documents/NARMD-Not-Another-Removable-Media-Disconnector/ta-p/2779526</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;We are using this script to provide a slightly more user-friend CDROM and floppy disconnect environment. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can easily disconnect all CDROMS with &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="code"&gt;Get-VM | Get-CDROMDrive | Set-CDROMDrive -Connected $False -Confirm:$False&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However you have little control over the above process, and might disconnect things that are actually in use. This script presents a list of VM's whose CDROM(s) or Floppie(s) are connected now, or are set to connect at startup, then prompts the operator to continue. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the operator confirms the action, it will go ahead and disconnect all the CDROMs and Floppies and uncheck the Connect At Startup, but at least the operator knows what's happening. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want a log file you can invoke this as follows: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="code"&gt;.\removableDrives.ps1 | Tee-Object C:\Logs\removableDrives.log&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's a sample console session (up to the prompt) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN __default_attr="courier new" __jive_macro_name="font"&gt;
VM: Server1 (PoweredOff)
  CD/DVD Drive 1 Connected=True ConnectAtPowerUp=True
  Floppy Drive 1 Connected=False ConnectAtPowerUp=False
VM: Server2 (PoweredOff)
  CD/DVD Drive 1 Connected=True ConnectAtPowerUp=True
  Floppy Drive 1 Connected=True ConnectAtPowerUp=True
VM: Workstation3 (PoweredOff)
  CD/DVD Drive 1 Connected=True ConnectAtPowerUp=True
  Floppy Drive 1 Connected=False ConnectAtPowerUp=False
VM: DomainController1 (PoweredOn)
  CD/DVD Drive 1 Connected=True ConnectAtPowerUp=True
  Floppy Drive 1 Connected=False ConnectAtPowerUp=True
Do you want to disconnect all removable drives, and disable the connect
  at startup?  If you don't see any VMs everything is OK and you should
  select N here.  Type Y or N:
&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The script is here for full-text searching, and is also attached. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN __default_attr="courier new" __jive_macro_name="font"&gt;"removableDrives.ps1 Version 1.0a starting" 
connect-viserver ($env:computername + "." + $env:userdnsdomain) | out-null 


Get-Vm | Where-Object {
(((Get-CDDrive -VM $_ | Where-Object { (($_.ConnectionState.Connected -eq $True) -or ($_.ConnectionState.StartConnected -eq $True))} ) -ne $Null) `
-or `
((Get-FloppyDrive -VM $_ | Where-Object { (($_.ConnectionState.Connected -eq $True) -or ($_.ConnectionState.StartConnected -eq $True))} ) -ne $Null))
} | %{
"VM: " + $_.Name + " (" + $_.PowerState + ")"
Get-CDDrive -VM $_ | ForEach-Object { " " + $_.Name + " Connected=" + $_.ConnectionState.Connected + " ConnectAtPowerUp=" + $_.ConnectionState.StartConnected }
Get-FloppyDrive -VM $_ | ForEach-Object { " " + $_.Name + " Connected=" + $_.ConnectionState.Connected + " ConnectAtPowerUp=" + $_.ConnectionState.StartConnected }
}

if ("Y" -eq (Read-Host `
("Do you want to disconnect all removable drives, and disable the connect `n" + `
" at startup? If you don't see any VMs everything is OK and you should `n" + `
" select N here. Type Y or N"))) {
Get-Vm | Where-Object {
(((Get-CDDrive -VM $_ | Where-Object { (($_.ConnectionState.Connected -eq $True) -or ($_.ConnectionState.StartConnected -eq $True))} ) -ne $Null) `
-or `
((Get-FloppyDrive -VM $_ | Where-Object { (($_.ConnectionState.Connected -eq $True) -or ($_.ConnectionState.StartConnected -eq $True))} ) -ne $Null))
} | %{
"VM: " + $_.Name + " (" + $_.PowerState + ")"
Get-CDDrive -VM $_ | ForEach-Object { Set-CDDRIVE -CD $_ -StartConnected $False -Connected $False -Confirm:$False | %{ " Changed " + $_.Name} }
Get-FloppyDrive -VM $_ | ForEach-Object { Set-FloppyDRIVE -Floppy $_ -StartConnected $False -Connected $False -Confirm:$False | %{ " Changed " + $_.Name} }
}
} 

"removableDrives.ps1 finished."&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Oct 2008 16:58:25 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Documents/NARMD-Not-Another-Removable-Media-Disconnector/ta-p/2779526</guid>
      <dc:creator>SCampbell1</dc:creator>
      <dc:date>2008-10-21T16:58:25Z</dc:date>
    </item>
  </channel>
</rss>

