Sunday, June 15, 2008

Windows PowerShell : PowerShell & OpenXML

PowerShell & OpenXML

Eric White just posted an amazing set of Cmdlets on CodePlex.  They allow you to use PowerShell to manipulate OpenXML documents to do all sorts of fun things, like create graphs from the output of PowerShell, automatically generate documents from XML, and extract comments from a document.  Below is an 8-minute video introducing you to the technology and a blog post with more details.

clip_image001
PowerTools for Open XML Introduction
(Video)

Blog:

http://blogs.msdn.com/ericwhite/archive/2008/06/11/processing-open-xml-documents-server-side-using-powershell.aspx

Get PowerTools For Open XML

Windows PowerShell : PowerShell & OpenXML

Windows PowerShell : Working With Web Services (Post CTP2 V2 Feature)

Blog of Windows PowerShell team. Improving the world one-liner at a time.

Working With Web Services (Post CTP2 V2 Feature)

Let me start by first apologizing for sharing some information that you are not going to be able to go out and try right away.  During one of the interactive Q&A sessions at TechEd, people asked about working with Web Services.  I referred to a feature that we were working on and then Hal Rottenberg asked me to blog about some of the details.  I'm not sure that this is a good idea because while we have it coded up and in the nightly builds, that is not a guarantee that it will make it into the next version (we often have to cut features in order to create bandwidth to increase the quality of other features).  That said, I'm going to go out on the limb a bit and share with you what we are working on.

First let's start with motivation (you should always start with motivation.  If you know WHY someone  is doing something, it is easier to get things in focus and provide meaningful feedback).  PowerShell is ALL about helping you get your job done with the minimal amount of effort (I've been thinking about calling this the "Cheap EATs" model where EAT stands for "Effort to Accomplish Task").   With that comes the observation that we live in an evolving world.  To accomplish your task, you need to easily access a wide range of technologies.  That is why we invest in giving you great access to WMI, ADSI, COM, XML, .NET, ADO, etc etc.  More and more things are now available as Web Services so we want to make it easy for you to get at them as well. 

As such, we have speced and implemented the cmdlet:  New-WebServiceProxy.    This command connects to a Web Service and generates a .NET proxy to that service.  Let me show you how it works using a web service which works with USZIP codes

See PowerShell Blog Post for code!

Windows PowerShell : Working With Web Services (Post CTP2 V2 Feature)

Taylor Brown's Blog : Hyper-V WMI – Configuring Automatic Startup/Shutdown/Recovery Action’s For Virtual Machines

 

Hyper-V WMI – Configuring Automatic Startup/Shutdown/Recovery Action’s For Virtual Machines

Hyper-V virtual machines have configuration options that control what happens when the parent/host server shuts down, start’s up, or if a virtual machine’s worker process terminates unexpectedly.  The first two conditions (parent/host shutdown, startup) are pretty self explanatory but what would cause a worker process to terminate?  There are a couple reasons, one would be if someone terminates the process, another would be if the process detects an security attack coming from the virtual machine, others reasons could be if there was bad hardware or a programming error (i.e bug) in either Hyper-V or another component in the system…

The default Automatic Startup Action is to start the virtual machine if it was running when the server was shutdown.  Another option is to always startup the virtual machine irrespective of the state of the virtual machine when the server was shutdown. The last option is none – this translates to leave the virtual machine off or saved when the server starts up.

The default Automatic Shutdown Action is to save any running virtual machines.  There are two other options, first is to turn off any running virtual machines and second is to shutdown any running virtual machines using the shutdown integration component.  The shutdown is forced – so any open/running programs will be terminated.  If the shutdown request fails the vm will be turned off – this can happen for many reasons primarily because the IC’s aren’t installed or if the guest is in safe mode/booting up.

The default Automatic Recovery Action is to restart the virtual machine, the other options are to revert to the last snapshot if one exists or none – which again equates to leaving the virtual machine off.

There is one additional option that I wanted to discuss briefly is Automatic Startup Action Delay, this is the amount of time to wait after the server reboot before taking the automatic startup action.  The default is zero – meaning take the action immediately.  This option could be very helpful for some servers – if you have lower and higher priority virtual machines you might want to delay the startup of your low priority virtual machines.

So here’s some code:

$VirtualSystemManagemntService = get-wmiobject -class "Msvm_VirtualSystemManagementService" -namespace "root\virtualization"
foreach ($Vm in Get-WmiObject -Namespace root\virtualization -Query "Select * from Msvm_ComputerSystem Where Description='Microsoft Virtual Machine'")
{
   $SettingData = Get-WmiObject -Namespace root\virtualization -Query "Associators of {$Vm} Where ResultClass=Msvm_VirtualSystemGlobalSettingData AssocClass=Msvm_ElementSettingData"
   $SettingData.AutomaticStartupAction = 0 #None=0, Restart if Previously Running=1, Always Startup=2
   $SettingData.AutomaticShutdownAction = 0 #Turn Off=0, Save State=1, ShutDown=2
   $SettingData.AutomaticRecoveryAction = 0 #None=0, Restart=1, Revert to Snapshot=2
   $SettingData.AutomaticStartupActionDelay = [System.Management.ManagementDateTimeconverter]::ToDmtfTimeInterval((New-TimeSpan -Minutes 10))
   $VirtualSystemManagemntService.ModifyVirtualSystem($Vm, $SettingData.PSBase.GetText(1))
}

ENJOY!

Taylor Brown
Hyper-V Integration Test Lead
http://blogs.msdn.com/taylorb

Taylor Brown's Blog : Hyper-V WMI – Configuring Automatic Startup/Shutdown/Recovery Action’s For Virtual Machines

Windows Vista Help: Keyboard shortcuts

Windows Vista Keyboard shortcuts

Keyboard shortcuts can make it easier to interact with your computer because you don't need to use the mouse as often.

Windows Vista Help: Keyboard shortcuts

Noah Coad : Windows Hot Keys with AutoHotKey

Windows Hot Keys with AutoHotKey

AutoHotkey_logoI’m a big fan of keeping my hands on the keyboard as much as possible and having real quick easy ‘one-touch’ access to my favorite apps, web sites, and tasks.  It’s just amazing how much more productive one can be when using the keyboard instead of the mouse.  Think of any common app you use in which you have a keyboards shortcut memorized, Ctrl-C to copy, Ctrl-V to paste, IE? Alt-D for the address bar, Word? Ctrl-S to save, Vista? Win key for the Start Menu, etc now imagine the power of having most all of your common tasks that quickly available, yup, pure power.

Now here’s the ultimate hotkey tool, AutoHotKey.  It is a simple ‘scripting’ like app.  Not only can you create hotkeys, but also script other parts of Windows, but I’ll focus this post on the hotkeys.  It is open source, been around a long time, is small, takes little memory, has a great help doc, a strong community, and is easy to use.

Noah Coad : Windows Hot Keys with AutoHotKey

 

Looks like a good tool!

Michiel Wories' WebLog : SQL Server Powershell is here!

- SQLPS – a minishell that gives you a complete pre-configured Powershell with all of SQL Server’s extensions preloaded.

- SQL Server Agent integration – A new job subsystem for Powershell

- SQL Server Management Studio Integration – context menus on every applicable node in Object Explorer (with connection context reuse. Including SQL security!)

- Four new Providers! – new providers for SQL Server relational engine, Registered Servers, Data Collection, and SQL Server Policy Management

- SQLCMD integration – SQLCMD compatible script execution within Powershell (reuses the SQL Server connection context, and even database context of the provider!)

- SQL Server Policy Management integration – Allows evaluation of any Policy

- Various other cmdlets – support the provider, such as conversion of a SMO Urn to a Powershell path, encoding and decoding of SQL identifiers.

- SQL Server Powershell redist – allows you to install SQL Server Powershell with your application or on any machine you need to have it on (this still being built so with the caveat it may be shipped later, or being cut altogether – don’t flame me yet).

Michiel Wories' WebLog : SQL Server Powershell is here!

Monday, June 9, 2008

Blog Archive