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:http://blogs.msdn.com/jmstall/archive/2007/03/04/debugging-cmdlets.aspx
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
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
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???
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 ...