{"id":8631,"date":"2007-01-29T16:40:40","date_gmt":"2007-01-29T16:40:40","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2007\/01\/29\/virtual-machine-managers-powershell-support\/"},"modified":"2019-02-18T13:20:48","modified_gmt":"2019-02-18T20:20:48","slug":"virtual-machine-managers-powershell-support","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/virtual-machine-managers-powershell-support\/","title":{"rendered":"Virtual Machine Manager&#8217;s PowerShell Support"},"content":{"rendered":"<p>One of the cornerstone features of <a href=\"http:\/\/www.microsoft.com\/systemcenter\/scvmm\/evaluation\/overview\/default.mspx\">System Center Virtual Machine Manager<\/a> (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 <strong>Rakesh Malhotra<\/strong> (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&#8217;s scripting experience (the VMWare script came from their website:  <a href=\"http:\/\/www.vmware.com\/community\/thread.jspa?messageID=348638&amp;#348638\"><span style=\"font-family:Courier;font-size:12pt\">http:\/\/www.vmware.com\/community\/thread.jspa?messageID=348638&amp;#348638<\/span><\/a><span style=\"color:black;font-family:Courier;font-size:12pt\"> )<\/span>.\n<\/p>\n<h3>Script to Disconnect Drives from Running Virtual Machines\n<\/h3>\n<p>\n\u00a0<\/p>\n<h2><span style=\"font-family:Courier;font-size:12pt\"><span style=\"color:black\">#!\/bin\/bash <br \/># http:\/\/www.vmware.com\/community\/thread.jspa?messageID=348638&amp;#348638<br \/>vmwarelist=`vmware-cmd -l`\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<br \/>vmwarelist=`echo $vmwarelist | sed -e <\/span><span style=\"color:navy\">&#8216;s\/ \/*\/g&#8217;<\/span><span style=\"color:black\">`\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<br \/>vmwarelist=`echo $vmwarelist | sed -e <\/span><span style=\"color:navy\">&#8216;s\/.vmx\/.vmx \/g&#8217;<\/span><span style=\"color:black\">`\u00a0\u00a0\u00a0\u00a0<br \/><\/span><span style=\"color:navy\">for<\/span><span style=\"color:black\"> vm in $vmwarelist <br \/><\/span><span style=\"color:navy\">do<\/span><span style=\"color:black\">\n\t\t\t\t<br \/>   vm=`echo $vm | sed -e <\/span><span style=\"color:navy\">&#8216;s\/*\/ \/g&#8217;<\/span><span style=\"color:black\">`\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<br \/>   vm=`echo $vm | sed -e <\/span><span style=\"color:navy\">&#8216;s\/ \\\/\/*\/g&#8217;<\/span><span style=\"color:black\">`<\/p>\n<p>\t\t\t<\/span><span style=\"color:navy\">if<\/span><span style=\"color:black\"> [ `vmware-cmd <\/span><span style=\"color:red\">&#8220;$vm&#8221;<\/span><span style=\"color:black\"> getstate | sed -e <\/span><span style=\"color:navy\">&#8216;s\/getstate() = \/\/&#8217;<\/span><span style=\"color:black\">` = <\/span><span style=\"color:red\">&#8220;on&#8221;<\/span><span style=\"color:black\"> ]<br \/>   then<br \/>   echo Looking @ $vm<br \/>   IDEBUS=`seq 0 1`<br \/>\n\t\t\t<\/span><span style=\"color:navy\">for<\/span><span style=\"color:black\"> i in $IDEBUS;<br \/>\n\t\t\t<\/span><span style=\"color:navy\">do<\/span><span style=\"color:black\"><br \/>      echo BUS : $i<br \/>\u00a0\u00a0\u00a0\u00a0  IDEDEVICE=`seq 0 1`<br \/>\n\t\t\t<\/span><span style=\"color:navy\">for<\/span><span style=\"color:black\"> j in $IDEDEVICE;<br \/>\n\t\t\t<\/span><span style=\"color:navy\">do<\/span><span style=\"color:black\"><br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 PRESENT=`vmware-cmd <\/span><span style=\"color:red\">&#8220;$vm&#8221;<\/span><span style=\"color:black\"> getconfig ide$i:$j.present | cut -f3 -d <\/span><span style=\"color:red\">&#8221; &#8220;<\/span><span style=\"color:black\">`<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span><span style=\"color:navy\">if<\/span><span style=\"color:black\"> [ $PRESENT = <\/span><span style=\"color:red\">&#8220;true&#8221;<\/span><span style=\"color:black\"> ]<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 then<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0TYPE=`vmware-cmd <\/span><span style=\"color:red\">&#8220;$vm&#8221;<\/span><span style=\"color:black\"> getconfig ide$i:$j.deviceType | cut -f3 -d <\/span><span style=\"color:red\">&#8221; &#8220;<\/span><span style=\"color:black\">`<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><span style=\"color:navy\">if<\/span><span style=\"color:black\"> [[ $TYPE == <\/span><span style=\"color:red\">&#8220;atapi-cdrom&#8221;<\/span><span style=\"color:black\"> || $TYPE == <\/span><span style=\"color:red\">&#8220;cdrom-image&#8221;<\/span><span style=\"color:black\"> ]]<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0then<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0   echo Found CDROM on IDE$i:$j<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0   vmware-cmd <\/span><span style=\"color:red\">&#8220;$vm&#8221;<\/span><span style=\"color:black\"> disconnectdevice ide$i:$j<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0fi<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 fi<br \/>      done<br \/>   done<br \/>   fi<br \/>done<\/span><br \/>\n\t\t<\/span><\/h2>\n<h3>SCVMM PowerShell\n<\/h3>\n<p>\n\u00a0<\/p>\n<p style=\"margin-left: 36pt\"><span style=\"font-size:12pt\"><strong><span style=\"font-family:Courier\">$vms = Get-VM | where {$_.VMState <\/span><span style=\"font-family:Calibri\">\u2013<\/span><span style=\"font-family:Courier\">eq <\/span><span style=\"font-family:Calibri\">&#8216;<\/span><span style=\"font-family:Courier\">Running<\/span><span style=\"font-family:Calibri\">&#8216;<\/span><\/strong><span style=\"font-family:Courier\"><strong>}<\/strong><br \/><strong>$vms | Get-DVDDrive    | Set-DVDDrive    <\/strong><\/span><span style=\"font-family:Calibri\"><strong>\u2013<\/strong><\/span><span style=\"font-family:Courier\"><strong>NoMedia <\/strong><br \/><strong>$vms | Get-FloppyDrive | Set-FloppyDrive <\/strong><\/span><span style=\"font-family:Calibri\"><strong>\u2013<\/strong><\/span><span style=\"font-family:Courier\"><strong>NoMedia <\/strong><\/p>\n<p><\/span><\/span>\n\t<\/p>\n<p>Take a minute and compare the 2 scripts and ask the following questions:\n<\/p>\n<ol>\n<li>How long did it take to write this script?\n<\/li>\n<li>Do I understand what this script is REALLY doing?\n<\/li>\n<li>How comfortable would I be changing this script and putting it on my production servers?\n<\/li>\n<li>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?\n<\/li>\n<li>At the end of the day, is this script going to save me time and money or cost me time and money?\n<\/li>\n<\/ol>\n<p>I think you&#8217;ll find different answers for the different scripts.\n<\/p>\n<p>Cheers!\n<\/p>\n<p>Jeffrey Snover [MSFT]<br \/>Windows PowerShell\/Aspen Architect<br \/>Visit the Windows PowerShell Team blog at:    <a href=\"http:\/\/blogs.msdn.com\/PowerShell\">http:\/\/blogs.msdn.com\/PowerShell<\/a><br \/>Visit the Windows PowerShell ScriptCenter at:  <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\">http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx<\/a>\n\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8631","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/8631","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=8631"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/8631\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=8631"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=8631"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=8631"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}