Image Conversion

  I needed to convert some images from bmp to gif for a web site I’ve been working on.  I figured that I could script this pretty easy – here’s what I came up with.  It’s a little more general than I needed, and I thought it might be useful to others.  Anyway, it’s useful… Read more

Duplicate Files 2

A long time ago I posted a filter (AddNote) for adding notes to objects.  Some time later I posted a function (Get-MD5) for calculating the MD5 hash of a file and somebody asked how that could be used in a script to list all the files in a given folder that are very likely the… Read more

Duplicate Files

Need a way to check if two files are the same?  Calculate a hash of the files.  Here is one way to do it:   ## Calculates the hash of a file and returns it as a string. function Get-MD5([System.IO.FileInfo] $file = $(throw ‘Usage: Get-MD5 [System.IO.FileInfo]’)) {   $stream = $null;   $cryptoServiceProvider = [System.Security.Cryptography.MD5CryptoServiceProvider];… Read more

Adding Notes

  A while back I mentioned that there was a way of adding notes to objects in the shell. Here is one way to do it: ## Adds a note to the pipeline input. filter AddNote([string] $name, $value) { $mshObj = [System.Management.Automation.MshObject] $_; $note = new-object System.Management.AUtomation.MshNoteProperty $name, $value $mshObj.MshObject.Members.Add($note); return $mshObj } As you… Read more

MshObject and Methods that take object

Every once in a while people ( including me) run into trouble calling methods that take object.  Why?  Well, as I told you earlier objects in MSH are wrapped by an invisible MshObject.  As it turns out that this invisible object is not always so invisible.  Take a look at the following:   MSH>$key =… Read more

Support for Existing apps in Monad

Monad provides strong support for existing apps and technology.  If you use native cmdline exes, vbscripts, batch files, perl scripts etc to manage and maintain windows, you can pretty much use them the same way from monad as you would from cmd.exe.   For example, I am used to findstr.exe and xcopy.exe. I can use… Read more

Did you know? #4

Did you know that you can access most of the Cmdlet base class APIs through script using the $executioncontext variable? -Jeff Jones… Read more

Did you know? #3

Did you know that you can put constraints on variables using the same attributes as cmdlet parameters?Unfortunately we had to postpone the language support for this but you can still do it using new-object.MSH > $a = “foo”MSH > $varA = get-variable aMSH > $varAName                           Value—-                           —–a                              fooMSH > $varA.Attributes.Add($(new-object System.Management.Automation.ValidateLengthAttribute -arg 1,10))MSH > $a… Read more

Did you know? #2

Did you know that you can make a variable automatically propagate to new scopes by using the AllScope option? Normally when you enter a new scope variables are not copied from the parent scope. Instead we do a lookup for the variable when requested. Anytime the variable is written to it happens in the local… Read more