Condividi tramite


VMM Script Series, part 5 - ShowDVDMediaCollisions

I’m publishing some of the scripts I have written for VMM.  These are each based on specific customer asks or conversations that lead me to go sleepless in trying to solve the problems myself.  I am very interested in your feedback, especially if you would like to offer a change to improve efficiency or effectiveness.

ShowDVDMediaCollisions

This script is designed to gather data on how each VM is physically connected to optical media and present it in such a way that an admin could quickly track down conflicts between two VMs.  This resolves the case of a VM that is unable to start because the connection to DVD media is already in use.  For each VM that is mapped to a physical DVD/CD drive, the script provides which host it is on and which drive it is connected to.

This presents the data as one line per VM mapped to a physical drive.  That satisfies my need for this issue but if you would prefer to output an array of VMs with the host and drive information as properties.  See the Get-NetworkMap script for an example.

Notes

In each of the scripts for this series, I have noted any manually assigned variables at the top of the script just under the header.  For this script you will want to update your VMM server name.

In each of the scripts for this series, I have added a line to load the VMM snap-in.  This way it can be run from any machine, including a workstation, where the VMM console is installed by right clicking on the file and choosing “run”.  If you run the script from within VMM you will get a few lines of error text that the snap-in is already loaded.  You can either ignore this, or comment out the line if it bothers you.

Screen Shots

 image

Script

disclaimer: this script is not supported in any way. I have posted the code rather than the .ps1 file so that you can review it, modify it to make it your own, and test it before trusting it in a production environment. now this is your code, I am not responsible for its use.

    1: # ------------------------------------------------------------------------------
    2: # Show DVD Media Collisions
    3: # ------------------------------------------------------------------------------
    4: # blogs.technet.com/offcampus
    5: # version 1.0
    6: #
    7: # Description
    8: #  Useful for displaying Optical Media mapped to more than 1 VM on the same host
    9: #
   10: # ------------------------------------------------------------------------------
   11:  
   12: write-host $args
   13:  
   14: # All variables in the script with customizable values are mapped here for convenience
   15: $VMMServerName = "v-vmm-01"
   16:  
   17: # Load Snap-Ins
   18: Add-PSSnapin Microsoft.SystemCenter.VirtualMachineManager 
   19:  
   20: # Begin Script
   21: Get-VMMServer $VMMServerName | out-null
   22: $VM = Get-VM
   23:  
   24: $LocationVMMap = @{}
   25: foreach ($entry in $VM)
   26: {
   27:  
   28:       foreach($connection in $entry.VirtualDVDDrives){If ($connection.HostDrive -ne $null){write-host "$($entry.Name) on $($entry.VMHost) is connected to DVD drive $($connection.HostDrive)"}}
   29:       #$entry.Name | %{$LocationVMMap += @($entry.VMHost, )}
   30: }