Virtual Machine Manager’s PowerShell Support

PowerShell Team

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

0 comments

Discussion is closed.

Feedback usabilla icon