Life of a techno-guru
Monday, December 24, 2007
  Debugging Powershell Cmdlets
This is great! The ability to actually use Visual Studio to debug cmdlets is awesome!

Check out this article on the .NET debugging blog:
  Windows Powershell v1.0 Problem
First of all ... I just created by first Cmdlet last week! The bad part? It doesn't work. Well, it doesn't work as expected, I should say. Let me give you a brief overview of the issue I ran into.

I recently decided to go ahead and start developing a set of cmdlets to manage a Microsoft Systems Management 2003 Server. Since we use SMS 2003 at my company, I figured it would be cool to expose the functionality through Powershell in case we wanted to script/automate SMS "stuff." I know that there are some existing SMS cmdlets out there, however these seem to target SMS clients rather than servers.

I started out by writing a cmdlet called Get-SMSCollections that did simply that ... it retrieved a list of SMS collections from an SMS server that is specified as a parameter. I ran into a bit of a bind, however, when trying to run this cmdlet. I'm currently getting an error message stating
: "format-default : Value was either too large or too small for an Int32." Now, I assume, naturally, that this message is coming from the format-default cmdlet, and some value I'm passing to it from my cmdlet is larger or smaller than an Int32 can handle. I'm really at odds as to what exactly this value is, however. Please note that the yellow warning text is coming from an Exception handler in my cmdlet and is not actually reflective of the real problem (it's just some static text I wrote in, in case anything fails). Now, since the error message is coming from format-default, I figured that I'd try something else to see what happens: Get-SMSCollections | Select-Object name,collectionID. This command actually works, and outputs the names and collection IDs of all my SMS collections! Now, that tells me that something, somewhere, some sort of data is messing up the format-default cmdlet.

I wish I knew what it was ...

The really weird thing though, is that I can run a Select-Object on any of the properties individually, and successfully retrieve them! So, what sort of data is Powershell trying to retrieve that it's unable to display???
Friday, December 21, 2007
  Odd Powershell FileSystemProvider Behavior
So, I've been working with Powershell more and more recently. I ran into a rather interesting ... bug, at least, I think it is anyway. The other day I decided to use Powershell instead of my normal command prompt to mount a WIM file to a folder on the filesystem, so I could view/edit it. I ran the command, and was told that the folder successfully mounted to a folder on the root of my c:\ drive. As per my personal custom, I quickly did a dir (alias for Get-ChildItem in Powershell) to make sure the folder was there (don't ask me why, but I do ... it's just habit). Surprisingly enough, however, the folder disappeared!

After opening up Windows Explorer, and traversing the folder structure, I knew something had to be up. I did an actual dir command in the regular command prompt, and it showed up. So, I guess what the problem is, is some sort of bug in the FileSystemProvider .NET class, which is the provider used in the Get-ChildItem Cmdlet to browse an NTFS (at least) filesystem.

I'm kinda curious to know if anyone else has noticed this same behavior ...
My life of learning various things about technology including network administration, development, and 3D design

Location: Chicago, Illinois, United States
January 2006 / February 2006 / March 2006 / May 2006 / June 2006 / July 2006 / August 2006 / September 2006 / October 2006 / November 2006 / December 2006 / January 2007 / February 2007 / March 2007 / April 2007 / May 2007 / June 2007 / August 2007 / December 2007 / January 2008 / March 2008 / April 2008 / June 2008 / July 2008 / September 2008 / December 2008 / January 2009 / February 2009 / March 2009 / May 2009 /

Powered by Blogger