Using Consolas in PowerShell Plus on a 64 bit machine

I love the Consolas Font for code. I spent a while trying to get PowerShell Plus to use the font in the interactive console. I noticed that when I went to save my settings I got a Console Settings windows just like the console for CMD and PowerShell out of the box.

It kept going back to Lucida Console.  I added consolas with the PS Plus Add font utility but that didn't do the trick on my 64 bit machine.

I found this article on Scott Hanselman's Blog and it seemed to do the trick.

Add a REG_SZ with name 00 and value Consolas to HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont

Note that you need to reboot.

PowerShell Plus 2.0 Ships!

The great folks over at Idera have released PowerShell Plus Professional 2.0. Once you use it, you'll never go back to cmd.

Plus (no pun intended) they have support for C#, VB, and a great XML editor.

Go and get a free 14 day trial now and use the 2 weeks to find a way to convince your boss that it is worth so much more than the $79.00 price tag.

Roles and Features Part 2

I have been playing with a tool called servermanagercmd which is a commandline tool which functions like ServerManager. It allows you to install different Roles, Features, and Role Services in Windows Server 2008. I mentioned in an earlier post that you can output it to an XML file and use Powershell to look at what is installed.

There is an -inputpath parameter that takes an answer.xml file. You would think that you could go to one server, do a servermanagercmd -query role.xml and then take that file to another server and do a servermananagercmd -inputpath role.xml and it would install all the roles and services that were on the original server. Yeah.. that would be nice, but no such luck. They are two different XML Schemas that apparently have nothing to do with one another.

<rant>

To further complicate the issue, servermangercmd is used in the full version of Windows 2008. But what if you wanted to install or remove roles in Windows 2008 Core. Forget servermanagercmd, its not there. Instead you have to use two different commands, ocsetup and oclist. OC standing for "Optional Component" ?

oclist in Core is the same as servermanagercmd -query

ocsetup is servermanagercmd -install

To screw things up even more, the aliases for the roles are not even the same between the two tools. Just an example, in the full version with servermanagercmd you add the feature called Failover-Clustering. In core, you use ocsetup to install FailoverCluster-Core.

Completely inconsistent, no intuitive, and unnecessarily complex.

</rant>

Perhaps what would be cool is a PowerShell function that could at least convert the output of servermanagercmd -query query.xml and turn it into an xml file that could be used by servermanagercmd -input input.xml. Any PowerShell XML Ninjas up for the challenge ?

Andy

Viewing Roles and Features with PowerShell

I am in the process of deploying a fairly large TS Server Farm with Windows Server 2008. You probably know that in 2008, you have roles and features that can be added to the Operating System. In fact, PowerShell shows up as a feature in 2008.

All of these roles and features are managed through an MMC called ServerManager. It's fairly intuitive to add or remove roles and features using this tool. There is also a command line version called servermanagercmd.

I just started playing with this and you can use servermanagercmd to install or remove roles, and you can also use it to query what is installed. The cool thing about the query feature is that it can dump it to an XML file.

So check this out

   1: servermanagercmd -q rolesandfeatures.xml
   2: $xml = [xml](gc rolesandfeatures.xml)
   3: $roles = $xml.get_documentelement()
   4: $roles
   5: $roles.role
   6: $roles.role | ? {$_.Installed -eq "true"} | ft DisplayName
   7:  
   8: DisplayName
   9: -----------
  10: Terminal Services
  11: Web Server (IIS)

 

Their is also input functionality built into the tool and I am sure that this is reversible. I'll keep you posted on how that goes.

 

Andy

New-HyperVVm

I recently had the need to be able to create a VM on a few of our Hyper-V servers at work. I found a great article by The Virtual PC Guy on how to create a new VM. I took what he had and extended the functionality a bit.  To manage Hyper-V, for now, we are pretty much stuck with WMI. However, Virtual Machine Manager will help us out a bunch. In the meantime, we can start with WMI. I figured it never hurts to know what is going on under the hood anyway.

One key piece of functionality that was not included was the ability to override the default location for new VM's when they are created. This is critical to us as we are using a SAN and have dedicated LUN's for our clustered VM's. So now that you have the background, here's the code

   1: function New-HyperVVM {
   2:         param   (
   3:                         [string]$Hypervhost = "localhost",
   4:                         [string]$Vm = "VM Courtesy of PowerShell",
   5:                         [string]$location = "C:MyVirtualMachines$vm"
   6:                         )
   7:         $wmiClassString = "\" + $Hypervhost + "rootvirtualization:Msvm_VirtualSystemGlobalSettingData"
   8:         $wmiclass = [WMIClass]$wmiClassString
   9:         $newVSGlobalSettingData = $wmiClass.CreateInstance()
  10:         $newVSGlobalSettingData.psbase.Properties.Item("ExternalDataRoot").value = $location
  11:         $newVSGlobalSettingData.psbase.Properties.Item("ElementName").value = $Vm
  12:         $VSManagementService = gwmi MSVM_VirtualSystemManagementService -namespace "rootvirtualization" -ComputerName $Hypervhost
  13:         $GlobalSettings  = $newVSGlobalSettingData.psbase.GetText(1)
  14:         $VSManagementService.DefineVirtualSystem($GlobalSettings, $ResourceSettings)
  15: } 

This is up on Poshcode. I highly recommend you be a good PowerShell community member and start sharing your code up here. If you haven't heard about their plans for this site, its awesome!

You can hear Joel and Hal talk about it on this episode of the  PowerScripting podcast.

New-HyperVVm

I recently had the need to be able to create a VM on a few of our Hyper-V servers at work. I found a great article by The Virtual PC Guy on how to create a new VM. I took what he had and extended the functionality a bit.  To manage Hyper-V, for now, we are pretty much stuck with WMI. However, Virtual Machine Manager will help us out a bunch. In the meantime, we can start with WMI. I figured it never hurts to know what is going on under the hood anyway.

One key piece of functionality that was not included was the ability to override the default location for new VM's when they are created. This is critical to us as we are using a SAN and have dedicated LUN's for our clustered VM's. So now that you have the background, here's the code

 

.posh li.li2, .posh li.li1 { list-style-type:decimal-leading-zero; white-space:nowrap;}.syntax .posh { overflow: auto; background-color:#eaeaea; border:1px solid #dddddd; border-width: 1px 1px 0px 1px;}.syntax .poshcredit {background-color:#eaeaea;border-bottom:1px solid #dddddd;color:#666666;font-size:85%;overflow:hidden;padding:0.5em 1em;}/* GeSHi (c) Nigel McNie 2004 (http://qbnz.com/highlighter) */.posh .de1, .posh .de2 {font-family: 'Courier New', courier, monospace; font-weight: normal;}.posh {font-family: monospace;}.posh .imp {font-weight: bold; color: red;}.posh li {background: #ffffff;}.posh li.li2 {background: #f8f8f8;}.posh .kw1 {color: #666699; font-weight: bold;}.posh .kw2 {color: #333399; font-weight: bold; font-style: italic;}.posh .kw3 {color: #660033;}.posh .co1 {color: #666666; font-style: italic;}.posh .comulti {color: #666666; font-style: italic;}.posh .es0 {color: #000099; font-weight: bold;}.posh .br0 {color: #66cc66;}.posh .st0 {color: #009900;}.posh .nu0 {color: #cc66cc;}.posh .me1 {color: #003366;}.posh .me2 {color: #003366;}.posh .re0 {color: #0066cc; font-style: italic;}.posh .re1 {font-style: normal;}.posh .re2 {color: #000066;}.posh .re3 {color: #660033; font-weight: bold;}.posh .re4 {color: #003366;}
  1. function New-HyperVVM {
  2.         param   (
  3.                         [string]$Hypervhost = "localhost",
  4.                         [string]$Vm = "VM Courtesy of PowerShell",
  5.                         [string]$location = "C:MyVirtualMachines$vm"
  6.                         )
  7.         $wmiClassString = "\" + $Hypervhost + "rootvirtualization:Msvm_VirtualSystemGlobalSettingData"
  8.         $wmiclass = [WMIClass]$wmiClassString
  9.         $newVSGlobalSettingData = $wmiClass.CreateInstance()
  10.         $newVSGlobalSettingData.psbase.Properties.Item("ExternalDataRoot").value = $location
  11.         $newVSGlobalSettingData.psbase.Properties.Item("ElementName").value = $Vm
  12.         $VSManagementService = gwmi MSVM_VirtualSystemManagementService -namespace "rootvirtualization" -ComputerName $Hypervhost
  13.         $GlobalSettings  = $newVSGlobalSettingData.psbase.GetText(1)
  14.         $VSManagementService.DefineVirtualSystem($GlobalSettings, $ResourceSettings)
  15. }
downloadThis Script brought to you by PoshCode

This is up on Poshcode. I highly recommend you be a good PowerShell community member and start sharing your code up here. If you haven't heard about their plans for this site, its awesome!

You can hear Joel and Hal talk about it on this episode of the  PowerScripting podcast.