Welcome to MSDN Blogs Sign in | Join | Help

In Praise of TypeConverters - Spread the Love

I just got through reading Scott Hanselman's blog entry:  TypeConverters: There's not enough TypeDescripter.GetConverter in which he referenced  Jesse Liberty's blog entry: Did You Know That... Type Converters allow you to use property attributes in Complex Types and decided to pile on.

Developers - you should stop what you are doing and get TypeConverters in focus.  Here is the big picture way to think about it:  As developers, our mission in life is to make the lives of others easier by providing them the functions they need in they way they need them.  TypeConverters play a huge role in the mission.

TypeConverters are one of the many the unsung heroes behind the magic of PowerShell.  Think about the code you write, think about the code your customers write.  An amazing amount of time and effort goes into coding around impendence mismatches:

  • That API gave me an A but this API needs a B.
  • I can easily get a string but I need an object of type A.

This impendence mismatches cause conceptual and code friction.  Think of TypeConverters as the grease in the object model that make things work together easily.  As a developer, you should take a look at the code you/your customers have to write and consider where a typeconverter could make things easier. 

Traditional languages have the disadvantage of requiring the developer to know about and use the TypeConverter.  The magic of PowerShell is that we do all of that for the user.  We know the TYPE of the data that the user has and we know what TYPE is needed.  We'll go through lots of hoops to make things "just work" including calling constructors, Parse() methods and TypeConverters.  Abhishek Agrawal wrote a good blog Extending PowerShell with Customer TypeConverters where he describes how to write a TypeConverter and then how to register it with PowerShell so we can use it in our type coercion engine.

Users:  I'd love to hear from you about any examples where you think we should have type convertors and don't.

Cheers!

Jeffrey Snover [MSFT]
Windows Management Partner 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

Remoting with PowerShell QuickStart

PowerShell V2 introduces a new capability which allows you to remotely manage machines in your organization. I will give a basic overview of PowerShell remoting here and follow it up with some adavanced topics later. Are you ready for the fun..

A remote interaction involves 2 endpoints – Client and a Server. The same computer or system can act both as a client and as a server.

Configuration

To enable an endpoint for PowerShell remoting you need to do the following:

Step 1: Install PowerShell CTP2 of PowerShell V2

Step2: Install CTP of WinRM

Step 3: Configure WinRM for PowerShell remoting. This can be done from a PowerShell Console using the following steps

(a)    Open PowerShell console in elevated prompt

(b)   Run $pshome\configure-wsman.ps1 script.

The above script will prepare your machine for remoting. This script will enable an endpoint both to act as a client and as well as a server.

PowerShell depends on WinRM for transport of data between endpoints. WinRM implements WS-Management a SOAP-based protocol for the management of servers etc. The good thing about this protocol is it is based on HTTP. So all the packets are going on Port 80 (by default) and you don’t need to open any other port for PowerShell remoting.

Using the Power

The beauty of PowerShell remoting is that all the cmdlets/scripts you have from V1 work as is everywhere (as long as PowerShell is installed on the server). So you develop your cmdlet/scripts once and you can remotely execute them with PowerShell as is without making any changes. The only dependency being the cmdlet/script you want to execute should be accessible on the remote box.

Let me show you some examples:

PS C:\> #my current machine

PS C:\> $env:computername

KRISCV-JHOOM

PS C:\> icm kriscv-lh { $env:computername }

KRISCV-LH

PS C:\>

The above example gives a glimpse of powershell remoting. Here I ran “$env:computername” locally and then on a remote machine from my local machine. I showed a new command “icm” here. “icm” is an alias for invoke-command cmdlet. This cmdlet takes the following pattern:

 

Invoke-command <ExecutionContext>  { <script block to run in the context>}

 

In my above “kriscv-lh” is the execution context. In this case it is a destination computer name.  So, essentially I have asked invoke-command to run the script “{$env:computername}” on the remote machine. This is the cmdlet you should use for remoting in CTP2 of Powershell V2. This cmdlet internally creates a connection with the machine “kriscv-lh”, runs the command on the machine, gets the output from the remote machine to the local machine, displays the output and then closes the connection.

 

You can pretty much do anything on the remote machine as you would on the local machine. Administrator of the remote machine however has the complete control of restricting you.

 

The following example shows you a way of finding free disk space on the remote machine:

 

PS C:\> $env:computername

KRISCV-JHOOM

PS C:\> icm kriscv-lh {gwmi win32_logicaldisk | select deviceid,freespace}

 

deviceid                 freespace                ComputerName             RunspaceId

--------                          ---------                ------------                           ----------

A:                                                               kriscv-lh                         8ce689c2-87a2-4e38-83...

C:                       44054937600                 kriscv-lh                          8ce689c2-87a2-4e38-83...

D:                                                              kriscv-lh                          8ce689c2-87a2-4e38-83...

 

Estentially whatever you have learned with V1 of PowerShell can be used with PowerShell remoting.  Lets convert the above example to show the freespace in GB instead of bytes:

 

PS C:\> icm kriscv-lh {gwmi win32_logicaldisk | select deviceid,freespace} | select deviceid,@{Name=

"freespace(GB)";Expression={$_.freespace/1gb}},computername

 

deviceid                                             freespace(GB)           ComputerName

--------                                                     -------------                 ------------

A:                                                                               0               kriscv-lh

C:                                                   41.0060882568359              kriscv-lh

D:                                                                               0               kriscv-lh

 

Notice what I have done here. The command in bold above is run on the remote machine kriscv-lh and the rest of the pipeline is run on the local box ie.,”select-object” cmdlet is run on the local machine. PowerShell remoting ensures objects are written onto the pipeline and hence you can leverage the complete power of PowerShell by working directly with an object.

 

You can apply the same concept to multiple machines. The following examples gets the free disk space from multiple machines:

 

PS C:\> icm kriscv-lh,kriscv-jhoom {gwmi win32_logicaldisk | select deviceid,freespace} | select dev

iceid,@{Name="freespace(GB)";Expression={$_.freespace/1gb}},computername

 

deviceid                                             freespace(GB)       ComputerName

--------                                                      -------------                  ------------

C:                                                182.064617156982       kriscv-jhoom

D:                                                136.152328491211      kriscv-jhoom

E:                                                7.60776519775391       kriscv-jhoom

F:                                                1.76084136962891       kriscv-jhoom

G:                                                                           0        kriscv-jhoom

A:                                                                           0        kriscv-lh

C:                                               41.0063934326172       kriscv-lh

D:                                                                           0        kriscv-lh

 

Notice I am running the command on 2 machines and running select-object cmdlet on the local box to filter the data.

 

There are so many things I want to talk about this CTP which I will do in the coming weeks. For the time being install the CTP, try out our new features and most importantly, if possible, give us your feedback.

 

Have a great weekend!!

 

Thanks

Krishna Vutukuri[MSFT]

Windows PowerShell Development

This posting is provided “AS IS” with no warranties.

Posted by PowerShellTeam | 5 Comments
Filed under:

Fun with Script Cmdlets

 

Script Cmdlets are one of the coolest things about the newer version of PowerShell.  A Script cmdlet allows you to use all of the variety of cmdlet parameter sets inside of PowerShell functions.

Since Script Cmdlets are PowerShell functions, and the PowerShell engine prefers to run functions rather than commands, you can use Script Cmdlets to override an existing cmdlet.  You might want to do this to add or remove parameters from a cmdlet you use often.  Also, you might just want to see what a cmdlet’s parameters look like in a script cmdlet, so you can go write your own.

Luckily, Powershell  has a way to generate script cmdlets from an existing cmdlet.  Below is a script cmdlet, called New-ScriptCmdlet, that I’ll use to create other script cmdlets.

You can use this to create new script cmdlets from existing cmdlets in a couple of different ways:

# Create a new PowerShell cmdlet from an existing cmdlet

Get-Command Get-Command | New-ScriptCmdlet Get-Command  | Set-Content Get-Command.ps1

# Create a new PowerShell cmdlet from an existing cmdlet’s type

[Microsoft.PowerShell.Commands.GetProcessCommand] | New-ScriptCmdlet Get-Process | Set-Content Get-Process.ps1

# Creates a new PowerShell cmdlet from a random existing command and puts it into a file of the same name

 Get-Command | Get-Random | Foreach-Object {
    $cmdlet = $_
    $scriptCmdlet  = $cmdlet | New-ScriptCmdlet $cmdlet.Name
    $scriptCmdlet | Set-Content "$($cmdlet.Name).ps1"
}

Hope this helps,

James Brundage [MSFT]

function New-ScriptCmdlet()

{

cmdlet `

 -DefaultParameterSet Type

    param(

    [Parameter(ParameterSetName="Type",ValueFromPipeline=$true,Position=1)]

    [Type]

    $type,

   

    [Parameter(ParameterSetName="CommandInfo",ValueFromPipeline=$true,Position=1)]

    [Management.Automation.CmdletInfo]

    $commandInfo,

 

    [Parameter(Position=0)]

    [string]

    $name

    )

 

    Process

    {

        if (! $type) {

            if ($commandInfo.ImplementingType) { $type = $commandInfo.ImplementingType }

        }

 

        if ((! $type) -and (! $commandInfo)) {

@"

$(if ($name) { 'function ' + $name + '() {' })

cmdlet `

param()

begin {}

process {}

end {}

$(if ($name) {'}' })

"@              

        } else {

            if (! ($type.IsSubclassOf([Management.Automation.Cmdlet]))) {

                throw "Must provide a cmdlet to create a proxy"           

            }

            $commandMetaData = New-Object Management.Automation.CommandMetadata $type

            $proxyCommand =                                

@"

$(if ($name) { 'function ' + $name + '() {' })

$([Management.Automation.ProxyCommand]::Create($commandMetaData))

$(if ($name) {'}' })

"@

            $executionContext.InvokeCommand.NewScriptBlock($proxyCommand)                         

        }

    }

}

PowerShell Transactions QuickStart

The second CTP of PowerShell V2 (CTP2) introduces full engine support for transactions – groups of actions that can be finalized or undone in an all-or-nothing way. Wikipedia gives a great overview of transactions here: http://en.wikipedia.org/wiki/Database_transactions.

 

We put a ton of thought into how to expose this normally developer-centric concept in a way suitable for system administration and system administrators. We would LOVE to hear your feedback on what concepts or behaviours make sense, and especially which ones do not.

 

We didn’t get a chance to fully document these cmdlets in the CTP2, though, so here’s a quick start and primer to help you explore the feature.

 

Using transactions

PowerShell surfaces its support for transactions through the following cmdlets:


PS C:\Temp> gcm *transaction*

 

CommandType     Name

-----------     ----

Cmdlet          Complete-PSTransaction

Completes / Commits a transaction

 

Cmdlet          Start-PSTransaction

Begins a transaction

 

Cmdlet          Undo-PSTransaction

Rolls back a transaction

 

Cmdlet          Use-PSTransaction

Places the current PowerShell transaction in Transaction.Current, for direct .NET Scripting against transacted objects.

 

To start a transaction, call the Start-PSTransaction cmdlet. To use a cmdlet that supports transactions, call it with the –UseTransaction parameter. Being explicit about this parameter is crucial, as many cmdlets that support transactions can work equally well without one. Because of that, PowerShell only surfaces the transaction to the cmdlet when you supply this parameter.

PowerShell’s registry provider supports transactions on Vista. In addition, a utility class called System.Management.Automation.TransactedString supports transactions on all platforms.

Once you have completed the transactional work, call the Complete-PSTransaction cmdlet to make it final, or the Undo-PSTransaction cmdlet to discard the changes.

 

Here is an example session that illustrates these concepts:


PS C:\Users\leeholm> cd hkcu:\temp

PS HKCU:\temp> dir

PS HKCU:\temp> Start-PsTransaction

 

## Create a key. We didn’t specify the –UseTransaction parameter, so it is not being done in a transaction.

PS HKCU:\temp> New-Item WillStayBehind

 

 

   Hive: Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\temp

 

SKC  VC Name                           Property

---  -- ----                           --------

  0   0 WillStayBehind                 {}

 

 

## Create a key in the transaction

PS HKCU:\temp> New-Item WillGetRolledBack -UseTransaction

 

 

   Hive: Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\temp

 

SKC  VC Name                           Property

---  -- ----                           --------

  0   0 WillGetRolledBack              {}

 

 

## Get-ChildItem from outside of the transaction. You don’t see any of your transacted changes.

PS HKCU:\temp> Get-ChildItem

 

 

   Hive: Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\temp

 

SKC  VC Name                           Property

---  -- ----                           --------

  0   0 WillStayBehind                 {}

 

 

## Get-ChildItem from inside of the transaction. Your transacted changes are now visible.

PS HKCU:\temp> Get-ChildItem -UseTransaction

 

 

   Hive: Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\temp

 

SKC  VC Name                           Property

---  -- ----                           --------

  0   0 WillStayBehind                 {}

  0   0 WillGetRolledBack              {}

 

 

## Now, some transacted .NET scripting against the TransactedString object

PS HKCU:\temp> $transactedString = New-Object System.Management.Automation.TransactedString

PS HKCU:\temp> $transactedString.Append("Hello ")

 

## Append some text in the transaction.

PS HKCU:\temp> Use-PsTransaction -UseTransaction { $transactedString.Append("World") }

 

## From outside the transaction, the changes are not visible

PS HKCU:\temp> $transactedString.ToString()

Hello

 

## But from within the transaction, they are

PS HKCU:\temp> Use-PsTransaction -UseTransaction { $transactedString.ToString() }

Hello World

 

## Roll back the transaction

PS HKCU:\temp> Undo-PsTransaction

 

## Look at the registry, and only our non-transacted changes are there.

PS HKCU:\temp> Get-ChildItem

 

 

   Hive: Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\temp

 

SKC  VC Name                           Property

---  -- ----                           --------

  0   0 WillStayBehind                 {}

 

 

PS HKCU:\temp> Get-ChildItem -UseTransaction

Get-ChildItem : Cannot use transaction. No transaction has been started.

At line:1 char:14

+ Get-ChildItem <<<<  -UseTransaction

PS HKCU:\temp> $transactedString.ToString()

Hello

PS HKCU:\temp>

 

Developing for transactions – Cmdlet and Provider declarations

Cmdlets declare their support for transactions in a similar way that they declare their support for ShouldProcess:

[Cmdlet(“Get”, “Process”, SupportsTransactions=True)]

 

Providers declare their support for transactions through the ProviderCapabilities flag:

[CmdletProvider(“Registry”, ProviderCapabilities.Transactions)]

 

Developing for transactions – Participating in the PowerShell transaction

The PowerShell engine exposes transactions in a way that lets developers implement a transacted provider or cmdlet in the same way that they implement other transacted code.

The recommended pattern for developing isolated transacted code in traditional applications is this: http://msdn2.microsoft.com/en-us/library/ms229973.aspx

using(TransactionScope scope = new TransactionScope())

{

   ... // Perform transactional work here

 

   // No errors - commit transaction
   scope.Complete();

}

 

This is called implicit transaction management, and the code in the code block represents the entirety of the transacted operation. The TransactionScope object handles management of the ambient transaction, committing and rolling it back as necessary.

Since cmdlet and provider developers should not deal directly with transaction scopes (but still be able to easily port transacted code,) PowerShell gives a similar experience:

using(CurrentPsTransaction)
{
   ... // Perform transactional work here
}

 

The CurrentPsTransaction property returns an IDisposable object. This IDisposable object, through the System.Transactions explicit programming model (http://msdn2.microsoft.com/en-us/library/ms172146.aspx), sets the current ambient transaction to be the current PowerShell Transaction. Its dispose method restores the previous ambient transaction. Attempting to use this current transaction while no transactions are active generates an error. The other transaction cmdlets control the nesting and lifetime of these transactions.

This CurrentPsTransaction experience differs from the C# TransactionScope experience in two ways:

1)     The object returned by the CurrentPsTransaction property does not actually represent a transaction. It does not support a Complete() method, Rollback() method, or anything else. The user is in charge of these decisions, not the cmdlet or provider developer.

2)     The transaction persists beyond the end of the code block, as multiple cmdlets can participate in it. Although the transaction persists outside of the code block, it is not active / ambient outside of the code block. A cmdlet or provider author can easily write the following code to tightly control which operations are transacted:

using(CurrentPsTransaction)
{
   ... // Perform transactional work here
}
 
... // Perform non-transacted work here
 
using(CurrentPsTransaction)
{
   ... // Perform more transactional work here
}
 

 

Using the same pattern PowerShell has established for the ShouldProcess functionality, cmdlet and provider authors should check for an existing transaction if they can operate without one:

if(TransactionAvailable())
{
    using(CurrentPsTransaction)
    {
       ... // Perform transactional work here
    }
}

 

If the cmdlet or provider cannot operate without a transaction, they can simply use the CurrentPsTransaction property. If no transaction is available, PowerShell automatically generates an error.

 

--

Lee Holmes [MSFT]

Windows PowerShell Development

Announcing the release of Community Technology Preview-2 (CTP2) of Windows PowerShell V2

The Windows PowerShell Team is pleased to release the second Community Technology Preview (CTP2) of Windows PowerShell V2!

This release adds a plethora of new features. PowerShell remoting now allows a one-to-one interactive experience. Thought about partitioning and organizing PowerShell scripts? Use modules to create self-contained and reusable units. This release introduces transactions support in PowerShell engine and APIs along with an update to the Registry provider to support them. We introduced eventing support in Powershell engine for listening, forwarding and acting on management and system events. Support for multiple parameter sets in script cmdlets bring them to par with C# cmdlets. For the adventurous folks.... application developers can host PowerShell in IIS to support multiple remote PowerShell sessions in a single process. These are just a few of the new features we have packaged in this CTP2 release. Additionally this CTP2 includes some simple updates... like new parameters to several existing cmdlets. More feature descriptions and details are in the Release Notes and in the “about” topics included with the installation.

Reminder to the brave souls who want to use these bits in a production environment ... Don’t.

This CTP is not a beta. This software is a pre-release version. It will not work the way a final version of the software does. These CTP2 bits have not gone through rigorous testing. Even with these caveats, we hope you would try them out and let us know your feedback.

Last but certainly not least, V2 builds upon Windows PowerShell 1.0 by providing backward compatibility – your 1.0 cmdlets and scripts will run on this CTP2 (with the exceptions noted in the Release Notes - mostly new keywords/cmdlets). If a working 1.0 script doesn’t run on V2 and is not in the known list of exceptions, please tell us about it!

Download Windows PowerShell V2 CTP2 

Download WinRM 2.0 CTP (required for PowerShell remoting)

Hemant Mahawar [MSFT]
Program Manager
Windows PowerShell

Submitting Feedback

Please submit your feedback using the Connect Website (adding a CTP2: to the title), posting on the Windows PowerShell Discussion Group, or commenting on the Windows PowerShell Blog

MMS: What's Coming In PowerShell V2

MMS is going well.  Yesterday Dan and Bruce presented an Introduction To PowerShell talk and then we all presented a What's Coming In PowerShell V2 talk.  The slides are attached. 

Cheers!

Jeffrey Snover [MSFT]
Windows Management Partner 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

Posted by PowerShellTeam | 12 Comments

Attachment(s): SE02_Snover_v08.pptx

PowerShell Presence at MMS

It is great to see how prominent PowerShell is at this years MMS.   Here are some highlights so far:

  • All attendees where given a copy of Ed Wilson's PowerShell Step-by-Step book (included in their bag).
  • There are 9 sessions explicitly covering PowerShell (4 of which are dedicated to PowerShell)
    • PowerShell is included in quite a few other sessions but not as a featured element
  • There are 3 hands on labs
  • A Birds of the Feather session
  • There were LOTS of mentions in yesterday's Partner Keynote and then again in BobMu's Keynote.

Now that PowerShell has shipped in Windows Server 2008, the Microsoft machine has started to really kick in.

Jeffrey Snover [MSFT]
Windows Management Partner 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

MMS Talk: System Center Foundation Technologies

Yesterday, Bruce Payette and I delivered a talk on System Center Foundation Technologies which covered WMI, BITS, WSMAN, PowerShell Engine and the CLI/Scripting experience.  What we did was to walk System Center Virtual Machine Manager (SCVMM)'s architecture and then highlight how it uses these technologies to do its magic.  For each component we discussed its

  • Role of the technology
  • Availability(e.g. which platforms it was available on)
  • Future
  • Benefits
  • Effect on application architecture
  • Where to get more information.

Attached is the deck.

Jeffrey Snover [MSFT]
Windows Management Partner 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

Dynamics of Technology Adoption and Market Competitiveness

Today is Partner day at MMS where we have special sessions focused to the special needs of ISV and IHVs.  I'll be giving an 1.5 hour talk: System Center Foundation Technologies  in which I discuss the management technologies that ship in Windows that the System Center products build upon. 

Most, but not all, System Center products have been shipping for quite a long time so it presents a bit of challenge.  Whenever an new technology comes out, retrofitting an existing product to leverage it is a complex equation.  You might think that as soon as a new platform technology becomes available, products leap at the opportunity to convert to using it.   After all you get:

  • Advanced features
    • The team is dedicated to that technology so they bring expertise, passion, insight (scar tissue), etc to produce the best and most advanced features.
  • Ability to get "free-features" as that technology advances
    • These teams continue to innovate and push the envelope.  This is practical because they have a large # of customers which amortizes the investment. 
  • Shifting your bugs and testing  burden to another team.
    • One of my favorites.  Your ability to generate new features in your product is a function of how many calories you can apply to the problem.  If your dev staff is spending their calories on bug fixing, support costs and testing, it means fewer calories you can apply to new features.  Leveraging other people's code is a way to export your expenses to another team.
  • Reduction in training costs for your customer
  • Reduced debugging costs for your field people
  • Reduced documentation costs
  • ... many more benefits

Seems like a no-brainer right?  Hardly.  The team has to factor that against:

  • Addressable market (do these technologies run on the [downlevel] platforms that I'm trying to sell to.)
    • I've been shocked by how few platform providers understand the concept and yet it is the #1 go/no go question.  If you offer me a STUNNING new technology with UNDENIABLE benefits and INCREDIBLE economies but you offer it on the TRS-80 that has 0% market share, then my friend, the conversation is over.  At the end of the day the folks that consume platforms are the folks that SELL STUFF to people.  If using your platform reduces the number of people that they can sell to (the addressable market) .... well do I even need to finish that statement?
    • This is why I am super hard core about shipping management technology downlevel. 
    • It turns out that management technology is hyper affected by the addressable market issue.  If you are building some user or server application, you just need to convince someone to buy it for some box.  In this scenario, you can make the case for upgrading the box to the latest greatest components because the advantage your application AND the new box/platform brings is SO compelling that it overcomes the inertia for leaving things alone.

      But you run management software on ALL YOUR MACHINES.  So imagine the conversation that starts out, "you'll have to replace every machine in your enterprise but let me explain why that is actually a good idea".  This is why we are hyper affected, mgmt is a group activity not an individual activity.  If PowerShell only shipped in the latest/greatest OS, then as soon as the OS was the oldest OS in the enterprise, mgmt vendors would start leveraging it.  

      Yes there are hybrid models where under extraordinary circumstances, the vendor will "light up" when the platform is available.  Let me tell you that having been on the other side of this conversation and been responsible for some of these decisions when I worked in the CTO office at Tivoli - they are a pain in the butt.  You have a split code base, double the pain, half the pleasure.
  • Conversion costs. 
    • A lot of people think that when 3 teams are developed the same thing, you can SAVE money by having them converge on a common implementation.  That is both absolutely correct and absolutely wrong.  It is correct that in the LONG RUN, you save money.  It is wrong in that you have to fund an additional (4th) team and THEN fund the conversion of the existing products!
    • This is one of the reasons we have PARTNER DAY.  It is cheap and easy to leverage a platform technology if you haven't already developed your own solution.  That is why we tell partners both what we have and what we are developing so that they can make rational decisions about their own investments (e.g. focus somewhere else for a while or develop it in a way that can be swapped out to use our implementation when it is available).
  • Lost opportunity costs.
    • At the end of the day, this is the #1 impediment for teams to embrace new platform technologies.  Take the conversion costs discussed above.  At the end of the day, you'll do the math and look at the balance sheet and if 1) that is the only thing you looked at 2) you have a healthy business (e.g. you are not focused on surviving through the next 3 months) and 3) a moderately wise professional manager , you would conclude that right thing to do is to convert over ASAP. 
    • The real problem comes when they consider the resources required to do the work and WHAT OTHER FEATURES those resources could be developing!  In other words, what opportunities are lost by doing this work.  Most teams are wildly (overly?) optimistic about the impact their next set of features are going to have in the marketplace and therefore cutting any of them is very painful.

Then you have to consider the startups.  Startup efforts have no existing code and have a PASSION of leveraging other peoples code (thus incurring all the benefits of the first list) and catapulting themselves to new levels of competition by writing the code that they and only they could write.  Leveraging the platform technologies means that every turn of the crank puts them at greater and greater levels of functionality with little to no costs while they get to focus on truly competitive features.  In the meantime, their competition that didn't pick up the new technology is spending the time and effort fixing bugs, duplicating features or falling behind.

Turn the crank once and there adopters have improved by a bunch and the non-adopters haven't.  It is uncommon (but not unheard of) for one turn of the crank to produce a decisive advantage in the marketplace.  There are too many other factors in the equation.  But turn that crank a second and a third time and it can be devastating (literally!) [to the competition].

So you might look at all this and ask, "when should a team leverage a platform technology?"  That is the question every team must deal with and solve by themselves.  Using the platform and NOT using the platform are both bets.  You need to look at the details, the upsides/downsides and put your future on the line (pretty good theme given that MMS is being held in Vegas!).

In my talk today, I'll be going through a couple examples of both.  I'll discuss Exchange 2007 which retrofitted their existing architecture to take advantage of PowerShell and layer their entire Admin GUI over PowerShell.  I'll also discussion SC Virtual Machine Manage (SCVMM) which is a V1 product and was able to leverage a number of the platform technologies our team produces (WMI, BITS, WS-MAN, PowerShell). 

If you think SCVMM V1 is awesome, you just wait until we turn the crank on our platform technologies!

Cheers.

Jeffrey Snover [MSFT]
Windows Management Partner 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

Get-Random

I saw THIS posting over on Mark Minasi's forums that caught my eye.  It gives you a random help file under the motto of: "A powershell help file a day, keeps Don Jones away".  :-)

Don responded pointing out one of our new V2 cmdlets:  Get-Random.  Since that cat is out of the bag and Get-Random is so cool, let's explore it:

PS>Get-Help Get-Random

NAME
    Get-Random

SYNOPSIS
    Gets a random number or selects objects randomly from a collection.


SYNTAX
    Get-Random [-Count [<Uint32>]] [[-InputObject] [<psobject>]] [-SetSeed [<in
    t>]] [<CommonParameters>]

    Get-Random [-Minimum [<Object>]] [[-Maximum] [<Object>]] [-SetSeed [<int>]]
     [<CommonParameters>]


DETAILED DESCRIPTION
    The Get-Random cmdlet gets a randomly selected number. If you submit a coll
    ection of objects to Get-Random, it gets one or more randomly selected obje
    cts from the collection.

    Without parameters or input, "Get-Random" returns a randomly selected 32-bi
    t unsigned integer between 0 and Int32.MaxValue (0x7FFFFFFF, 2,147,483,647)
    .

    You can use the parameters of Get-Random to specify a seed number, minimum
    and maximum values, and the number of objects returned from a submitted col
    lection.


RELATED LINKS


REMARKS
    For more information, type: "get-help Get-Random -detailed".
    For technical information, type: "get-help Get-Random -full".

 

PS> # Get A random number
PS> Get-Random
1163375074
PS>
PS> # Get a random number within a range
PS> Get-Random -min 10 -max 15
13
PS>
PS> # Get a random element
PS> "Tom","Dick","Harry" |Get-Random
Dick
PS> # Get a set of random elements
PS> "Tom","Dick","Harry" |Get-Random -count 3
Tom
Harry
Dick
PS> # Is it really random?  yup
PS> "Tom","Dick","Harry" |Get-Random -count 3
Dick
Harry
Tom
PS> # It works with any set of objects
PS> gps |get-Random -Count 2

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
    361      26    51316      55864   151   225.73   1700 svchost
   1570      16    68756      30300   276   457.43   2424 SearchIndexer


PS> gps |get-Random -Count 2

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
    316       8     3004       7368    40    36.61    604 services
    209       9    75740     137232   197 1,067.36   2760 dwm

 

At the end of the day, the cmdlets that manage the OS features need to come from those feature teams so you should not expect PowerShell to deliver a ton of those.  For instance, the AD team needs to deliver the AD cmdlets, the network team needs to deliver networking Cmdlets.  If you are not getting the cmdlets you need, you should knock on the doors of those feature teams.  Don't suffer in silence, complain.

PowerShell will deliver some management cmdlets but by and large, we are going to focus our efforts on utility cmdlets that work against anyones objects and make it a good deal for those feature teams to develop cmdlets.  Get-Random is just such a cmdlet.  I'll bet you a dollar to a doughnut that no feature team would ever prioritize Get-Random but it turns out that all of their customers will use it at some point.  PowerShell delivers it and thus the feature team's customers benefit.  That's the deal - you invest in writting cmdlets/providers and we invest in ensuring that that was a great investement by delivering a ton of functions to your customers.  How can you go wrong with that?

Enjoy! 

Jeffrey Snover [MSFT]
Windows Management Partner 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

Heading to Microsoft Management Summit (MMS) Where We'll Show PowerShell CTP2

A number of us are headed to Vegas this weekend to prep for MMS were we will be showing the latest and greatest PowerShell V2 features.  It pays to attend these conferences as you get the first look at our new stuff.  If you recall, CPT1 was released at IT Forum in Barcelona last year.   We are really excited to show off what we have been working on.  CTP2 is the largest/most expansive set of changes we've ever made to PowerShell.  I think it is going to take everyone a long time to comprehend the true magnitude and ramifications of what we are delivering in CTP2 - it is truly game changing. 

Those of you that are going to MMS are probably big WMI users.  If you are, then you DEFINATELY want to come to my What's New In PowerShell V2 talk on Wed and be sure to bring your drool buckets.  We've been listening to you.  We've also been drilling into the sort of scripts that you write and we think they stink.  I'm actually completely serious.  I'm not throwing a rock at YOU, I'm throwing it at US.  We've given you crummy tools and abstractions so the level of crap you have to deal with just to get your job done is completely insane.  I talked to one team whose WMI scripts took so long to run, that they started the second pass of the script before the first pass was done!   UNACCEPTABLE.   ABSOLUTELY UNACCEPTABLE.  We can and we will do better.  Come see what I mean on Wed. 

Dan Harmon and Bruce Payette are doing an Introduction to PowerShell talk.  This is truly an introduction talk so it is perfect if you are just starting with PowerShell but if you if you are hard-core PowerHead, you might get frustrated with this talk.  Our PowerShell Scripting for Wizards talk on Friday is the talk for you PowerHeads.  This is a V1 talk but it assumes that you are an experienced PowerShell user on your way to becoming a Wizard.  Bruce and I are giving this and if we don't make your head spin at least once - we'll have failed.  This is going to be unabashed hard-core Geek Porn.  :-)   You must be over 18 and be an experienced PowerShell user to attend.  Maybe we'll require people to write a REGEX or a WHERE clause to get in  :-)!!!

Just to be clear - that is going to be an EXTREMELY unstructured talk.  Well that's not quite it, we are going to have a structure but it is not going to be a traditional talk.  We have 1 slide (after the title Slide) and then it will be demo demo demo.  Bottom line - this talk is not for everyone but for the people it IS for, it should be fun.  Bruce and I are certainly looking forward to it.

As always, we'll post our