Virtual Machine Manager’s PowerShell Support

Virtual Machine Manager’s PowerShell Support

  • Comments 17

One of the cornerstone features of System Center Virtual Machine Manager (SCVMM) is PowerShell. They have built their entire GUI layered on top of PowerShell in the same way that Exchange 2007 did. A little while ago, I talked to Rakesh Malhotra (the Group Program Manager for SCVMM) about how things were going and he was very pleased with their bet on PowerShell. He talked about how their task-oriented Cmdlets provided a very user approachable scripting experience. I asked him for a few examples so he sent me a set of comparisons with VMWare's scripting experience (the VMWare script came from their website: http://www.vmware.com/community/thread.jspa?messageID=348638&#348638 ).

Script to Disconnect Drives from Running Virtual Machines

 

#!/bin/bash
# http://www.vmware.com/community/thread.jspa?messageID=348638&#348638
vmwarelist=`vmware-cmd -l`                    
vmwarelist=`echo $vmwarelist | sed -e
's/ /*/g'`        
vmwarelist=`echo $vmwarelist | sed -e
's/.vmx/.vmx /g'`    
for vm in $vmwarelist
do
vm=`echo $vm | sed -e
's/*/ /g'`                
vm=`echo $vm | sed -e
's/ \//*/g'`

if [ `vmware-cmd "$vm" getstate | sed -e 's/getstate() = //'` = "on" ]
then
echo Looking @ $vm
IDEBUS=`seq 0 1`
for i in $IDEBUS;
do
echo BUS : $i
     IDEDEVICE=`seq 0 1`
for j in $IDEDEVICE;
do
         PRESENT=`vmware-cmd
"$vm" getconfig ide$i:$j.present | cut -f3 -d " "`
        
if [ $PRESENT = "true" ]
         then
            TYPE=`vmware-cmd
"$vm" getconfig ide$i:$j.deviceType | cut -f3 -d " "`
            
if [[ $TYPE == "atapi-cdrom" || $TYPE == "cdrom-image" ]]
            then
             echo Found CDROM on IDE$i:$j
             vmware-cmd
"$vm" disconnectdevice ide$i:$j
            fi
         fi
done
done
fi
done

SCVMM PowerShell

 

$vms = Get-VM | where {$_.VMState eq 'Running'}
$vms | Get-DVDDrive | Set-DVDDrive
NoMedia
$vms | Get-FloppyDrive | Set-FloppyDrive
NoMedia


Take a minute and compare the 2 scripts and ask the following questions:

  1. How long did it take to write this script?
  2. Do I understand what this script is REALLY doing?
  3. How comfortable would I be changing this script and putting it on my production servers?
  4. If there is a problem in the middle of the night and the operations people need to review this script to understand what is going on, am I going to get a call?
  5. At the end of the day, is this script going to save me time and money or cost me time and money?

I think you'll find different answers for the different scripts.

Cheers!

Jeffrey Snover [MSFT]
Windows PowerShell/Aspen Architect
Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

Leave a Comment
  • Please add 8 and 4 and type the answer here:
  • Post
  • 1) Aliases can map to anything not just cmdlets that is why the parameter name is -VALUE

    2) We should have REMOVE-ALIAS.  Full stop.  We prioritized other features.  The way you do it is:

    Remove-Item Alias:name

    I'd appreciate the details for #4.  V2 should run V1 scripts with perfect fidelity modulo bug fixes.

    jps

  • Hi Jeffrey,

    I installed SCVMM 2008 R2, but I couldn't find the cmdlet Get-DVDDrive as you used in your article.  Can you please give me some pointers on how to use the powershell scripts shipped with SCVMM?

    Thanks,

    Weidong

Page 2 of 2 (17 items) 12