Archive for April, 2008

Someone sent this link as a “great article about Live Mesh” ... and it was so bad, that I just have to rant about it. Your 9th grade English teacher would have flunked you for this … it’s just a horrible example of the Anguish Languish.

Steve Gillmor has an analogy or a metaphor for everything (and I mean literally every paragraph). Most of them are bad, but some of them are truly awful, so I’m just going to pick on a couple to vent steam.

So it went with Microsoft, as the seeming invulnerability of Gates’ machine accelerated to the boundaries of global saturation. Though we tend to think of Google as the conqueror, the reality is that Microsoft has struggled most with itself, the victim not of decline but of lack of fuel — the very customers who created the megalith in the first place.

The who, did what?
megalith — [noun] ( ‘meh gE “lIth ) 1. a huge stone, esp. one used in prehistoric times as a monument.
First of all, megaliths are erected, not created. Secondly, they don’t use (or lack) fuel. Thirdly, they’re a bad counterpoint to “conquerors.” If you wanted to use that many metaphors in one sentence, you should have said something like this: though we tend to think of Google as the conqueror, the reality is that Microsoft has struggled most with itself, the victim of a decline like that of the Roman empire, and yet Google has still not dared challenge the megalith of Windows, propped up as it is by millions of customers around the world …

The microbigs can seem transcendent like Facebook or possessing the lifetime of a gnat like a thousand forgotten startups or neverwases (sic), but nowhere are the range of possible outcomes more encapsulated than Twitter.

First of all, “can seem transcendent” works, but “can seem possessing the lifetime of a gnat” doesn’t. But more importantly, if Facebook is your example of transcendent, then the “lifetime of a gnat” takes on a whole new meaning — maybe you meant to invoke the branding of Hotmail, or Yahoo!, or SlashDot. Finally, “Neverwases” might be okay in poetry, but isn’t this still a technology magazine?

Yes? Yes. So what you’re saying is that Google is a microbig. Yes, did I say that? No, but I didn’t ask that either and the answer is still yes. Bottom line: Microsoft can’t gain and retain traction with Mesh unless the answers are yes.

What?! Exactly who is he having this conversation with in his head, and why did he write it down on paper?

I hate to ask, but, what is a “Coke Classic question” ... and how did “When’s the Mac version?” get on any list of classic questions? Why are you asking questions without question marks? What is a “Net-grappling” product line? Incidentally, the mental image conjured by combining “flailing” with “grappling” is rather frightening. It’s a no wonder that there are so many comments on this post that say things like “what is he talking about?”

Steve claims that “orthogonal and complementary” is “MicroBig language” (by the way, can we get a little capitalization consistency on your made up words please?) but I’m pretty sure that these are terms usually used by the (it hurts to write this) BigBigs to assuage fears of internal competition, as in: Microsoft’s advertising assets and aQuantive’s complementary expertise… or Yahoo! is complementary to Microsoft and so on. The so-called MicroBigs are usually more concerned with disruptive and revolutionary.

Bah. Anyway.

A relatively new PowerShell user came into #PowerShell on IRC.FreeNode.net this week to ask a question about scripts and the pipeline, and the conversation went so well, that I thought I’d share it with you all in case it helps clear things up for you. We’ll call him “user” since he left before I could get his permission to paste this, and I’ve cleaned up, reordered and in a couple of cases added lines to make the conversation seem a little more linear than the chat really was.

user: Can you explain the distinction between $_ and a param in a script context?
Jaykul: I sure can. And I think I can do it simply … take an example script|function … actually, we’ll just use a scriptblock
Jaykul: it can have pipeline blocks, or not (the pipeline blocks are the BEGIN{...} PROCESS{...} END{...})
user: yeah, I’m with you
Jaykul: so if you pass a value via an argument, it’s present in all three blocks, and has the same value the whole time (unless you change it in your script)
user: really
Jaykul: But when you put that script in a pipeline, your BEGIN {} block is called first, and then for EACH item in the pipeline, powershell sets $_ and calls your PROCESS block, and finally, your END{} block is called after all pipeline items have been processed
Jaykul: Here, check this out (run it so you can see) (more…)

Microsoft is announcing a big new software + services product and platform this week (well, today, and tomorrow, apparently). It’s called Live Mesh (how much do you suppose mesh.com set them back?) and it’s primarily a synchronization platform — updates shared files across multiple devices (PC, Laptop, handheld, Mac … yes, they said Mac OS X support is coming). They have some of FolderShare in there, and some of Groove and some of FeedSync … initially, this looks like a folder sync and backup service (see their Mesh help files), but it’s designed to become so much more…

At the core is this concept that a single user has a “mesh” of devices, applications, and data that they regularly use. The Mesh Service persists the relationship between these various resources and authorizes access to them … The Mesh Platform means that ultimately, (down the road) customers will license applications and content to their mesh instead of to a specific computer, device, or application. Microsoft actually envisions apps running seamlessly across multiple devices “from the mesh” ... using Remote Desktop and the mesh software to enable that connectivity regardless of your network topology (meaning it can punch through firewalls because you’re running the client software on all the devices). That platform part could really transform the industry if they actually deliver on this cross-platform support for OS X … are they going to deliver a remote desktop server for OS X?

The most interesting part of this platform concept is that they’re trying to extend their OS and Application -based dominance to the web by making the web a part of this “combined experience and storage platform” and trying to reduce the pressure on consumers to choose between local storage and “storage in the cloud.” Thus, an important part of The Mesh Platform is the fact that each mesh object (be it a document, a picture, a song, or a blog post) can be dealt with in different ways on different platforms — so you might have a folder on your computer containing Word documents … which are transformed into blog posts via the mesh and the concept of synchronized feeds. This could revolutionize web development, if it’s done right. Imagine: a mesh object can be a range of cells in an Excel spreadsheet ... which could be published to the web … and edited … and synchronized … and the whole time you have explicit control over the location and custody of the data, and you have built-in support for groups, group memberships, group permissions and ownership, etc.

To sum up … will not just be another folder ...

  • The Mesh will deliver more reliable networking by using “the cloud” to relay communications if firewalls intervene.
  • The Mesh will allow publish/subscribe (pub/sub) infrastructure for any kind of change notification.
  • The Mesh will include “presence” awareness: who’s on, who’s using this, etc.
  • The Mesh will provide message-based news events.
  • The Mesh will be built on bidirectional “feed” sync with fully authenticated groups.
  • The Mesh will work in occasionally connected scenarios.

Am I interested? Maybe … I need to see some licensing and terms of service information which isn’t really available at the moment (since the whole thing is in a closed beta).

Some screenshots of the client portion of Live Mesh are on CNet, and webware has some analysis of the app portion as well — they seem to say that it will will include full Remote Desktop access to a Windows “Live desktop.”

In the #PowerShell IRC channel (on irc.freenode.net) we have a bot and pastebin (which is set up here on my site) ... if you paste something in the pastebin site, the bot posts a link to it in the IRC channel for you, so you don’t have to mess with copying the resulting URL and pasting it to the channel to ask for help.

I also run a version of pastebin that’s been modified for long term storage as the main PowerShell Script Repository (which is, among other things, the main repository for the PowerShell Community).

So, when someone showed me sprunge earlier today, along with a python script for pasting there … I couldn’t help but think that it would be nice to have that for our pastebin sites… so here it is, Send-Paste


## Send-Paste.ps1 (aka sprunge for Pastebin)
##############################################################################################################
## Uploads code to any pastebin.com based pastebin site and returns the url for you.
##############################################################################################################
## Usage:
##    get-content myscript.ps1 | Send-Paste "An example for you" "This is just to show how to do it"
##       would send the script with the specified title and description
##    ls *.ps1 | Send-Paste -Keep Forever
##       would flood the pastebin site with all your scripts, using filename as the title
##       and a generic description, and mark them for storing indefinitely
##    get-history -count 5 | % { $_.CommandLine } | Send-Paste
##       would paste the last 5 commands in your history!
##############################################################################################################
## History:
## v 2.0 - works with "pastebin" (including http://posh.jaykul.com/p/ and http://PowerShellCentral.com/Scripts/)
## v 1.0 - Worked with a special pastebin
##############################################################################################################
#function Send-Paste {
param(
   $Title,
   $Description="Automated paste from PowerShell console",
   $KeepFor="d",
   $Language="posh",
   $Author = $(Read-Host "Your name"),
   $url="http://posh.jaykul.com/p/"
)
   
BEGIN {
   $null = [Reflection.Assembly]::LoadWithPartialName("System.Web")
   [string]$data = $null;
   [string]$meta = $null;

   if($language) {
      $meta = "format=" + [System.Web.HttpUtility]::UrlEncode($language)
      # $url = $url + "?" +$lang
   } else {
      $meta = "format=text"
   }
 
   do {
      switch -regex ($KeepFor) {
         "^d.*" { $meta += "&expiry=d" }
         "^m.*" { $meta += "&expiry=m" }
         "^f.*" { $meta += "&expiry=f" }
         default {
            $KeepFor = Read-Host "Invalid value for 'KeepFor' parameter. Please specify 'day', 'month', or 'forever'"
         }
      }
   } until ( $meta -like "*&expiry*" )

   if($Description) {
      $meta += "&descrip=" + [System.Web.HttpUtility]::UrlEncode($Description)
   } else {
      $meta += "&descrip="
   }   
   $meta += "&poster=" + [System.Web.HttpUtility]::UrlEncode($Author)
   
   function PasteBin-Text ($meta, $title, $data) {
      $meta += "&paste=Send&posttitle=" + [System.Web.HttpUtility]::UrlEncode($Title)
      $data = $meta + "&code2=" + [System.Web.HttpUtility]::UrlEncode($data)
     
      # Write-Host $data -fore yellow
     
      $request = [System.Net.WebRequest]::Create($url)
      $request.ContentType = "application/x-www-form-urlencoded"
      $request.ContentLength = $data.Length
      $request.Method = "POST"

      $post = new-object IO.StreamWriter $request.GetRequestStream()
      $post.Write($data,0,$data.Length)
      $post.Flush()
      $post.Close()

      # $reader = new-object IO.StreamReader $request.GetResponse().GetResponseStream() ##,[Text.Encoding]::UTF8
      # write-output $reader.ReadToEnd()
      # $reader.Close()
      write-output $request.GetResponse().ResponseUri.AbsoluteUri
      $request.Abort()     
   }
}

PROCESS {
   switch($_) {
      {$_ -is [System.IO.FileInfo]} {
         $Title = $_.Name
         Write-Output $_.FullName
         Write-Output $(PasteBin-Text $meta $Title $([string]::join("`n",(Get-Content $_.FullName))))
      }
      {$_ -is [String]} {
         if(!$data -and !$Title){
            $Title = Read-Host "Give us a title for your post"
         }
         $data += "`n" + $_
      }
      ## Todo, handle folders?
      default {
         Write-Error "Unable to process $_"
      }
   }
}
END {
   if($data) {
      Write-Output $(PasteBin-Text $meta $Title $data)
   }
}
#}
 

Incidentally, the matching “Receive-Paste” script is just a matter wrapping a call to my wget for powershell in a script that lets you put just the ID in, and builds a url like http://powershellcentral.com/scripts/?dl=172 (notice the ?dl= part, that’s the important part) ...

I read some legal terms of service today that I just feel like I have to tell you about, because, well … a lot of people are talkinga bout Syncplicity, and signing up like mad because it’s free and provides “unlimited” storage. I just have to say, what these people are saying up front on their tour, and the legal contract that you’re agreeing to in the Terms of Service … are completely different.

Their tour says they provide unlimited storage

Syncplicity’s storage is unlimited, so you never need to worry about how many file, gigabytes, or what-have-you of bandwidth you have left. Ever.

Their terms of service say:

You acknowledge and agree that Syncplicity may, at its option, establish limits concerning Sync Files, including, without limitation, the maximum number of days that Sync Files will remain available via the Services or on the Site, the maximum size of any files that may be stored on or uploaded to the Site or Services and the maximum disk space that may be allotted to you …

Their tour says they back up your files immediately and continuously.

Syncplicity recognizes your data is important and we work hard to earn your trust. Beyond continuous backup of files, Syncplicity also gracefully and safely handles dangerous situations which can potentially cause data loss … Painlessly recover deleted files and previous versions of files.

Their terms of service say:

You acknowledge and agree that you should not rely on the Site, Syncplicity Content, Services and Sync Files for any reason…. Syncplicity will have no responsibility or liability for maintaining copies of Sync Files on our servers, and you are solely responsible for creating back-ups of your Sync Files outside of your use of the Site and Services for such purposes … you will be responsible for all costs and expenses required to backup and restore any data and information that is lost or corrupted as a result of your use of the Site, Syncplicity Content, Services and/or Sync Files.

It gets worse though, because the rest of their terms of service borrow every possible nasty trick in the book … They reserve the right to scan and access your computer and any files or data on it, and to modify their terms of servitude at any time ....

YOU ACKNOWLEDGE AND AGREE THAT BY UTILIZING THE SITE, SERVICES AND/OR SYNC FILES, TO PROVIDE YOU WITH THE SERVICES YOU CONSENT TO SYNCPLICITY ACCESSING AND/OR SCANNING (I) YOUR COMPUTER AND/OR ANY FILES, DATA OR INFORMATION THEREIN

Syncplicity reserves the right in its sole discretion, at any time, to modify, discontinue or terminate … these Terms of Service without advance notice … By continuing to use the Site or Services after Syncplicity has posted any modifications on the Site … you accept and agree to be bound by the modifications.

They’ll call the cops … or they won’t …

That stuff is what I normally look for in Phishy companies … this one is a new one though. Syncplicity isn’t content to just say that they’ll cooperate with any warrants issued against them, and help the police in any investigations to the full extent of the law. No, they’re going to be proactively reporting on you. In Soviet Russia, the computer locks you up.

Actually, the scariest bit about this is the freedom it gives them to do anything they want, whenever they want. I’ve emphasized a couple of phrases here, and included more of the quote than I normally would, so you can see I’m not taking them out of context:

Syncplicity may notify authorities or take any actions it deems appropriate, without notice to you, if Syncplicity suspects or determines, in its own discretion, that you may have or there is a significant risk that you have (i) failed to comply with any provision of these Terms of Service or any policies or rules established by Syncplicity; or (ii) engaged in actions relating to or in the course of using the Site or Services that may be illegal or cause liability, harm, embarrassment, harassment, abuse or disruption for you, Syncplicity Users, Syncplicity, any other third parties or the Site or Services.

The key thing that has to worry you here is that they can do whatever they want (regardless of the terms of the the rest of this agreement) if they feel (note that they will use their own discretion, not any legal standard) that there’s a risk that you might have broken one of their rules or a law (not to put too fine a point on it, but one assumes that they’ll be just as happy to enforce the laws of communist North Korea as they would to enforce the laws of the European Union or the United States).

Regarding ownership

Please don’t fall for a customer asking you to use this service to send them a copy of a file … As soon as you do, that other person can not only use it for whatever they want, but they can sublicense it to anyone they want for whatever reason.

While you retain all rights in any Sync Files, by using Site or Services, you hereby grant to Syncplicity a non-exclusive, worldwide, royalty-free, sublicensable, perpetual and irrevocable right and license to use and exploit such Sync Files as necessary to provide you with the Services. In addition, you hereby grant all other Syncplicity Users who you invite to access the Sync Files you indicate a non-exclusive, worldwide, royalty-free, sublicensable, perpetual and irrevocable right and license to use and exploit such Sync Files.

Oh, and last but not least … once they change the terms of service to include payment … don’t think you can just download all your files and shut off the service — once that term changes, if you want to cancel your account, they still get to keep all the files, and you can’t do anything about it. In fact, although you won’t be able to access your files, there’s no guarantee that those files will be deleted.

Any suspension, termination or cancellation will not affect your obligations to Syncplicity under these Terms of Service (including, without limitation, the rights granted by you to Syncplicity) ... we will have no further obligation to provide the Site or Services and all licenses and other rights granted to you by these Terms of Service will immediately cease.

You’ve been warned.

Here’s a snippet from the latest update to my resumé ... you’ll notice I struck out the “create” portion of the descriptions — as long as we just talk about maintenance and support tasks, everything you see here is what I did in just the last two weeks since one of my teammates transferred to a different division and our temp/contract was stolen away to a full-time position with a different company.


Software Engineer, Test Tools Development.


Lead developer for in-house software solutions for a 100-strong quality assurance team at a Fortune 500 company … responsible for creating and maintaining all custom software solutions and database systems.

  1. Create and maintain a randomized software test-case generation tool capable of managing hundreds of test projects with dozens of variables and using pseudo-random weighted generation to create thousands of test cases for each of our hardware and software tests.
  2. Maintain a custom HR tracking and reporting tool for billing internal customers based on hourly rates for work done testing hardware and software products for dozens of internal and external customers.
  3. Create and maintain a custom requirement and test-case tracking system for internal tracking of spec-based testing and reporting.
  4. Create and maintain a custom defect tracking system which interfaces with and provides metrics for over half a dozen different defect tracking systems (DDTS, ClearQuest, MS TFS, SourceForge, etc) used by the development teams we support.
  5. Create and maintain internal test-results reporting system capable of capturing test-case pass/fail/waive information and tying it to internal requirements and test case tracking systems as well as external defect and work-request tracking systems.
  6. Create and maintain various reporting systems providing charts and reports of counts and rates to support capacity planning, software quality metrics, test effectiveness and efficiency measures, software quality predictions etc, as well as tracking post-release defect discovery and analysis to improve the effectiveness of pre-release testing.

Work with a multitude of languages and technologies to provide the most effective solutions for each request in a timely manner on multiple platforms … from client apps and scripting solutions to cross-platform web apps.

  • Using Asp.Net with HTML/CSS/Javascript and VB.Net and C#.net to provide “AJAX” web-based applications.
  • Using PHP and Perl to provide web-based defect query and search services.
  • Using C#, Windows Forms and WPF to provide rich-client tools for test planning and test-case generation.
  • Using PowerShell, VBScript, TestBasic, and AutoHotkey to automate testing, as well as maintenance and data-entry tasks.
  • Using and maintaining SQL Server, SQL Reporting Services, and SQL Analysis Services to provide reporting and business intelligence and to support tool development.
  • Tracking work and changes in various source control and defect tracking systems such as VSS, ClearCase, ClearQuest, Bugzilla, SVN and TFS.

[crazy] 10 languages, 5 software platforms, 7 separate applications … and the apps I wrote myself (and am therefore most familiar with) seem to be the only ones that I’m not fielding support calls for multiple times a day. I need a vacation (or rather, a couple new coworkers). [surrender]

Fingers don’t fail me now! [whip]

Of course, in my spare time, I’m working on my capstone project for my Masters degree in Computer Science …

This is the second in an occasional series of tips for PowerShell users: short posts which don’t intend to give guidance, but merely a tip on a feature you may not be aware of, or maybe even answers to some of the recurring questions that come up in #PowerShell.

Fixing the “Current Directory” problem

The core of this tip is very simple: Windows tracks your application’s “current directory” ... and you can get and set this location using static methods of the System.IO.Directory class: SetCurrentDirectory and GetCurrentDirectory.

The reason this is showing up as a Power User Tip is that PowerShell doesn’t set this environment setting when you navigate — it uses it’s internal “PSProvider” architecture, and doesn’t differentiate between whether you’re in a FileSystem location or a registry location, or even a third-party provider. So, it never actually changes the current directory, and any console command or .net method you call which uses the current directory will most likely be in the wrong place — like, for instance:


$sw = New-Object System.IO.StreamWriter("NeatFile.txt")
$sw.writeline("I could write a lot of neat stuff here!")
$sw.close()
 

The problem is that now you don’t know where “NeatFile.txt” is — the “current directory” depends on how you launched PowerShell — most frequently it’s your $Home directory (equivalent to Env:HOMEDRIVE + Env:HOMEPATH — usually something like C:\Documents and Settings\YourName), but it could be your SystemRoot (C:\Windows) or the current directory of the app that launched PowerShell (eg: C:\Windows\System32 when you run it via “runas”). You can figure it out by running: [IO.Directory]::GetCurrentDirectory().

But here’s something more interesting: you can “fix” the problem by using [IO.Directory]::SetCurrentDirectory. There are a couple of catches, however: You can’t just use $pwd or Get-Location because you might be in the registry or some other location that’s not a Directory. And you can’t just use Get-Location -PSProvider FileSystem because even though it returns the current FileSystem provider path, the FileSystem provider supports “fake” PSDrives (eg: you could create a Scripts: drive like new-psdrive scripts filesystem "$Home\Scripts") and these aren’t actually supported by the .Net FileSystem. Luckily, PowerShell includes a Convert-Path cmdlet which was created for this very purpose: converting a path from a Windows PowerShell path to a native path supported by the underlying provider.

Without further ado, here’s a one-liner you can add to your prompt function:


[IO.Directory]::SetCurrentDirectory((Convert-Path (Get-Location -PSProvider FileSystem)))
 

[new] Edit: You can do the same thing using the System.Environment class, and it turns out that the ProviderPath is a property of the PathInfo object, perhaps you’ll find this syntax simpler:


[Environment]::CurrentDirectory=(Get-Location -PSProvider FileSystem).ProviderPath
 

The other day I was working on some scripts, trying to figure out how to do something new with WMI, and when I finally got it working, I started to copy and paste the commands I had typed into a script so that I could repeat the action in the future … and I realized that I could just use the Get-History cmdlet and export the CommandLine property of the history items to the clipboard! Wow, that’s such a timesaver …

Of course, once I thought of it, I figured that really, I should just write save them straight to a script, where I could delete the ones I didn’t want. Of course, I’m lazy, so I don’t want to type any more than I have to, and I figured this was worth turning into a script of it’s own! I’ve polished it a bit now, so that it automatically creates a script in my “Scripts” folder (which is included in my path) ... and in fact, I even went ahead and tweaked my Edit-File script (an idea I got from the PSCX guys) so that it accepts files from the pipeline so that I can write: save Test-Script 20 | edit to open the file right away.


## New-Script function
## Creates a new script from the most recent commands in history
##################################################################################################
## Example Usage:
##    New-Script ScriptName 4
##        creates a script from the most recent four commands
##    New-Script Clipboard -id 10,11,12,14
##        sends the the specified commands from the history to the clipboard
##    Notepad (New-Script ScriptName 20)
##        sends the most recent twenty commands to the script, and then opens the script in notepad
##################################################################################################
## As a tip, I use a prompt function something like this to get the ID into the prompt:
##
## function prompt {
##   return "`[{0}]: " -f ((get-history -count 1).Id + 1)
## }
##################################################################################################
## Revision History
## 1.0 - initial release
## 1.1 - fix bug with specifying multiple IDs
## 2.0 - use the current folder as the default instead of throwing an exception
##     - prompt to overwrite if not -Force
##################################################################################################

#function New-Script {
param(
   [string]$script=(Read-Host "A name for your script"),
   [int]$count=1,
   [int[]]$id=@((Get-History -count 1| Select Id).Id),
   [switch]$Force
)

# if there's only one id, then the count counts, otherwise we just use the ids
if($id.Count -eq 1) { 1..($count-1)|%{ $id += $id[-1]-1 } }
# Get the CommandLines from the history items...
$commands = Get-History -id $id | &{process{ $_.CommandLine }}

if($script -eq "clipboard") {
   if( @(Get-PSSnapin -Name "pscx").Count ) {
      $commands | out-clipboard
   } elseif(@(gcm clip.exe).Count) {
      $commands | clip
   }
} else {
   $folder = Split-Path $script
   if(!$folder) {
      # default to putting it in my "Windows PowerShell\scripts" folder which I have in my path...
      $folder = Join-Path (Split-Path $Profile) "Scripts"
   }
   if(!(Test-Path $folder)) {
      # if that fails, put it in the current path (on the file system)
      $folder = Get-Location -PSProvider "FileSystem"
   }
   # add the ps1 extension if it's not already there ...
   $file = Join-Path $folder (Split-Path $script -leaf)
   if(!(([IO.FileInfo]$file).Extension)) {
      $file = "$file.ps1"
   }
   # write an error message if the file already exists, unless -Force
   if((Test-Path $file) -and (!$Force)) {
      Write-Error "The file already exists, do you want to overwrite?"
   }
   # and confirm before setting the content if the file already exists, unless -Force
   $commands | set-content $file -Confirm:((Test-Path $file) -and (!$Force))
   Get-Item $file
}
#}
 

There’s way more script that is strictly needed here, but it’s mostly because I wanted to make typing the script extension and path optional, since I put almost all of my scripts in the same scripts folder, and the extension is always the same.

As you can see, you can choose to just grab the most recent X commands, or you can choose specific commands by id that you want to capture in the script. You can also output them to the clipboard, as long as you either have the PSCX snapin with out-clipboard loaded, or you have clip.exe (which is not included on XP).

This version of this script is in the PowerShell repository and if you make any improvements, you can submit them through the correction or amendment form …

This is an old post that’s been sitting in my queue for a long time, and I just finally thought I’d publish it, for what it’s worth. The word on the street was that SQL Server 2008’s PowerShell support is going to be limited.

I’m here to say: it’s not so much limited, as it it cautiously restrained. A lot of people were apparently hoping for a SQL Server provider like this demo one that could fully navigate tables and list their contents etc., but I think the SQL Team has decided not to allow that, and I think they probably did the right thing.

Honestly, a provider that can navigate into SQL datatables would be extremely frightening, to the point that it might need to be banned or blocked in some instances. Just imagine a SQL Server dba who’s brand new to PowerShell, but thinks that new provider sounds interesting … so he fires up PowerShell and switches over to the customer orders table (you know, the one with 2 million records of purchases) and does:


cd SQL:\Server\Northwind\Orders
ls | where { $_.ShipName -like "Robert *" }
 

Just think about that line for a second. Not only is it fetching every record in the table, it has to build a .net object for every single one. One of the most commonly used cmdlet’s in PowerShell is Get-Member, which we typically see used when you’re trying to figure out which properties are available on an item. Applied to the previous example, you can imagine doing something like this:


cd SQL:\Server\Northwind\Orders
ls | Get-Member
 

Now you’ve retrieved every record from the table … just for the sake of finding out what the columns are! You’re not even using the data. If you’re lucky, the memory use of creating 2 million System.Data.Row objects would cripple your dba’s PC before they were able to try something like this:


cd SQL:\Server\Northwind
ls |
 ForEach {
  $Property = $_ | gm |
   where { $_.Name -like "*Name" } |
   Select -First 1; $_."$($Property.Name)"
} | Where {$_ -like "Robert*"}
 

Anyway. Hopefully this counter example will be enough to not only make you feel better about using a cmdlet instead of a provider, but also to make some people think about how they choose to design things that can cause potentially crippling network traffic or server load. The thing is that although it’s possible to allow the -Filter parameter of Get-ChildItem (ls) to specify both a WHERE clause and a TOP count … that wouldn’t help unless you were sure your users would always filter that way instead of by passing it through | Where-Object.

As a side note: The management studio protects you from this sort of load on your system to some extent by caching data and limiting how many rows it pulls over at a time, but not as much as it could if it allowed you to reorder columns and sort them after you had retrieved the data. It also has the distinct advantage of not necessarily having to create .Net objects to pass into the pipeline for each row on the fly (although, maybe that’s how it works, I don’t know, but I would hope not).

Anyway, from what I’ve understood, the SQL powershell provider will let you navigate the schemas, and will provide some cmdlets to do queries that should replace some of the functions we’ve all been using to do queries. Maybe they’ll even provide something that can do built in paging, like: Get-SqlQuery “Select * from Northwind.Orders” -Next 10 …

Well, Microsoft has released its free Visual C++ 2008 Feature Pack for download — including a major update to MFC and an implementation of TR1 which includes smart pointers, regular expressions, containers and better random number generators.

The update to MFC is a fairly major overhaul, and includes components which provide the L&F(Look And Feel) of IE, Office 2007 (including the ribbon bar), Visual Studio (including Visual Studio docking and autohide windows), with support for Vista themes, and on-the-fly customization of toolbars and menus, according to Somasegar. The list goes on, and it honestly left me feeling conflicted — I mean, now that MFC has joined us in the 21st century, I’m almost tempted to actually use it …