Welcome to MSDN Blogs Sign in | Join | Help

Feedback Request: What language do you use to write Cmdlets?

Hello everyone. I’m the programming writer for the PowerShell developer audience and I would like to know what language you use to write cmdlets. This is a very unscientific survey, yet getting your replies will help me decide how to add VB.NET and C++ sample code in the documentation. The content that I’m writing is the Programmer’s Guide and SDK that you find on MSDN

 

Thank you in advance, and if you have any other documentation questions don’t hesitate to send me an e-mail at stevenel@microsoft.com

Steve Nelson

Published Wednesday, April 25, 2007 6:57 PM by PowerShellTeam

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Feedback Request: What language do you use to write Cmdlets?

I've done a few in C#, but may use JScript.net for the next one because I need to do lots of string parsing, object creation, and regular expression handling.

I've started with PowerShell script, but frankly it is not as good in comparision.  Very awkward to create objects and somewhat cumbersome to use regular expressions (compared to jscript).

Wednesday, April 25, 2007 2:55 PM by James Hugard

# re: Feedback Request: What language do you use to write Cmdlets?

I code all my cmdlets in C#.

If you're going to add a language, I would recommend making it C++/CLI only because there are so many existing converters out there that can convert C# to VB.NET (and vice versa), and those are both languages you can pretty much convert in your head once you see a few samples in both.

Wednesday, April 25, 2007 3:06 PM by jmanning

# re: Feedback Request: What language do you use to write Cmdlets?

c#

i just can't take vb seriously.

Wednesday, April 25, 2007 3:39 PM by Adrian Milliner

# re: Feedback Request: What language do you use to write Cmdlets?

I implore you not to bother with samples in different languages. I find they make the flow of the text harder to follow, because invariably the markup isn't quite correct when hiding some of the languages or the text is incomplete, and the pages don't seem to be intended to be read without a language filter. The samples typically only differ by syntax, so just pick a language and use it. Make it clear which one you go with.

I understand that there's some reluctance to take sides (or rather, pick a faction, given how similarly these languages are being used), but I find it a bit patronising to see the same thing three times. I'd much rather there was a separate section for "Important considerations in <Language>" with any poignant remarks spelled out explicitly, rather than hidden in a sample; in general, I believe MSDN relies too heavily on samples to make up for sloppy wording.

Wednesday, April 25, 2007 4:01 PM by James Slaughter

# re: Feedback Request: What language do you use to write Cmdlets?

Actually, never mind my last comment about JScript.net.  I just discovered two very interesting things that make working with regular expressions MUCH easier from script (and I'll stick to C# for creating cmdlets):

1) captures from the last -match call are available via $matches.  Therefore, I do not need to instantiate a System.Text[...].Regex object to create a regular expression.  I can use: 'if( $s -match "tag: (.*)" ) { $v = $match[1] }' instead!

2) the 'switch -regex' statement works like -match, in that the captures are available in the switch block!

switch -regex ($s)

{

 "Frob: (.*)" { $frob = $matches[1] }

 "Froz: (.*)" { $froz = $matches[1] }

}

However, I would still dearly like to see a more simple object model - something akin to jscript's dynamic objects makes a great deal of sense.

Wednesday, April 25, 2007 5:26 PM by JHugard

# re: Feedback Request: What language do you use to write Cmdlets?

The PowerShell Community Extension cmdlets are all written in C#.

Wednesday, April 25, 2007 6:56 PM by keith_hill

# re: Feedback Request: What language do you use to write Cmdlets?

I only have used C#.  I won't using any other languages in the foreseeable future.  -Thanks

Wednesday, April 25, 2007 7:00 PM by chrucci

# re: Feedback Request: What language do you use to write Cmdlets?

Absolutely C#.

I do like the argument for C++/CLI, though. Converting between VB and C# is so automatic that it's almost subconscious--though there's something to be said about how much better the C# language matches the concepts of .NET.

In contrast, C++/CLI is not as intuitive a jump to make. Furthermore, the advantages of using C++/CLI instead of C# or VB when wrapping native code are substantial. It's one of those things that you don't fully appreciate until you've done it a few times. This is important particularly because I would suspect that a lot of commandlets people write will be targeted toward bringing pre-existing technology into PowerShell.

Wednesday, April 25, 2007 7:43 PM by Tyler Larson

# re: Feedback Request: What language do you use to write Cmdlets?

I prefer C#.  Why not use the language that most closely resembles PowerShell?  After all, one of the goals of PowerShell is to create a solid "transition point" to compiled languages, is it not?  Also, most of the more recent MSDN articles (from what I've seen) that only show a single language's examples are generally written in C#.

Wednesday, April 25, 2007 7:53 PM by T-Bone

# re: Feedback Request: What language do you use to write Cmdlets?

C# and C++/CLI. I can't add a word to what Tyler Larson said.

Wednesday, April 25, 2007 9:10 PM by Roman Kuzmin

# re: Feedback Request: What language do you use to write Cmdlets?

I've been programming in some flavor of basic for close to 20 years.  I'd sure like to see more sample in VB, even though I've gotten pretty good at translating C# on the fly.

Wednesday, April 25, 2007 10:35 PM by Rick Wilkerson

# re: Feedback Request: What language do you use to write Cmdlets?

I also only use C# ... unless I'm writing something that's primarily a matter of interacting with Win32 APIs that aren't already exposed in the .Net Framework

Wednesday, April 25, 2007 10:57 PM by Joel "Jaykul" Bennett

# re: Feedback Request: What language do you use to write Cmdlets?

I use C# exclusively. It feels natural and sits nicely with the rest of the managed code of my app.

C++ examples will be nice to learn from.

Thursday, April 26, 2007 12:36 AM by Mohit

# re: Feedback Request: What language do you use to write Cmdlets?

Just for that reason I would include VB if you are asking for others besides C#.

C++/CLI would be my third choice, but people need to understand that VB can still do it. Just about EVERYTHING that can be done in C# can be done in VB. It is not second rate or third rate.

In the grand scheme of things, the only one that gets to the metal anymore is C++/CLI. So in the end having both C# and VB makes people feel that VB is still valid.

(I code a lot of SharePoint things in VB just to show that it can be done, not because it is any better)

Thursday, April 26, 2007 12:44 AM by Richard

# re: Feedback Request: What language do you use to write Cmdlets?

We use C#. We haven't tried any other language yet.

Thursday, April 26, 2007 1:32 AM by nikhilbhandari

# re: Feedback Request: What language do you use to write Cmdlets?

Same here.

I've done a few in C# but would love to see some C++/CLI sample code (and maybe port some of my native stuff to PS).

Thursday, April 26, 2007 2:38 AM by inline

# re: Feedback Request: What language do you use to write Cmdlets?

If I remember correctly, when they created the original .NET documentation base, it was decided that they would focus primarily on providing examples in VB and secondarily in C#, because it was assumed that C# programmers were able to do the mental translation between languages (while the same was not assumed of VB programmers). This decision has been of some frustration to me on certain occasions because doing that mental translation precludes the at-a-glance interpretation of example code.

That is, if you've been at it long enough, you can probably get a decent understanding of a piece of code without actually having to read it--just skimming will do. This ability is frustrated, however, when the code is in the "wrong" language. Even though you can read and understand it, it takes more effort than you'd care to expend.

With that in mind, it's worth pointing out that while VB programmers make up a significant portion of the developers working with .NET, the overlap between programmers who prefer VB and programmers would be interested in writing PowerShell commandlets is probably minimal. People who use VB with .NET are often the ones who would still be on VB6 if they could be. Remember how they tried to petition Microsoft reconsider? They're not going to give up cmd.exe either without a fight. People who develop for PowerShell, at least initially, are going to be those who are excited to try out new technology. Those users will have long since learned C#.

Thursday, April 26, 2007 2:56 AM by Tyler Larson

# re: Feedback Request: What language do you use to write Cmdlets?

I'm using C# almost exclusively for cmdlets.  Mainly this is because these cmdlets are intended to work with a system written in C#, and I like C#, so writing the cmdlets in that pretty much makes sense...

Thursday, April 26, 2007 5:08 AM by John

# re: Feedback Request: What language do you use to write Cmdlets?

I use VB. I know, I'm a throwback. But I wouldn't be on VB6 if I could. I *can*, if I want to, but I don't mind VB.NET. I'm excited about the new technology... I just like the VB syntax better, is all.

Some companies have internally settled on VB as a standard, for various reasons. If there were developing cmdlets, they'd want to see examples in VB. It has nothing to do with anyone's capability, it's just a company's desire to keep their internal code in a single language. Likely the decision dates back to the VB6 days when all they had were VB programmers, but there it is. C# isn't inherently "better" a language for most purposes; it's just different. After all, it's all MSIL in the end, no?

I'd be a strong supporter of providing examples in both C# and VB. Anything MS can do to make these technologies more accessible to a broader range of programmers is essential.

Thursday, April 26, 2007 10:25 AM by Don Jones

# re: Feedback Request: What language do you use to write Cmdlets?

I write cmdLets in C#, when working on a project in VB.NET i convert the C# code for aesthetic reasons to VB.NET with the various tools available.

I've been wanting to write one in PHP using Phalanger but i don't expect code samples for that, Once you start you'll be publishing samples in  IronPython, Ruby, COBOL or any other language that can be compiled for the .NET framework.

Since Powershell is supposed to provide a glide path to C# i'd stick with that.

Thursday, April 26, 2007 10:55 AM by Joris van Lier

# re: Feedback Request: What language do you use to write Cmdlets?

Please make the examples in C# so as to be consistent with every other Microsoft example, application block, etc. Anyone can translate on the fly while simultaneously learning PowerShell so naturally the VB programmers should translate.

Thursday, April 26, 2007 9:08 PM by Bill Booth

# re: Feedback Request: What language do you use to write Cmdlets?

C# C# C#

though supporting examples in other languages won't hurt. But i'd prefer more comprehensive documentation over more diverse language examples anyday.Also the glide between powershell scripts and C# based cmdlets is more natural syntaxwise the way that powershell is designed.

Friday, April 27, 2007 2:40 AM by karl prosser

# re: Feedback Request: What language do you use to write Cmdlets?

I haven't gotten a chance to write my own cmdlets yet, but I've been very excited over the idea of writing a cmdlet library for Python and utilizing both Python.Net and IronPython for them.

Friday, April 27, 2007 10:24 AM by Calvin Spealman

# re: Feedback Request: What language do you use to write Cmdlets?

Here is mine in order of preference:

-- Powershell :-) :-) :-)

-- IronPython

-- VB

-- C# (why must we still live with statement separators?!?!?)

Friday, April 27, 2007 4:20 PM by Mike Schinkel

# re: Feedback Request: What language do you use to write Cmdlets?

>> Please make the examples in C# so as to be consistent with every other Microsoft example, application block, etc. Anyone can translate on the fly while simultaneously learning PowerShell so naturally the VB programmers should translate.

I just read this. UGH! It's the C# programmers that have the skill to translate, VB is more for people who want to get things done and are not choosing a language based on what will most boost their egos.

If it is a choice between C# and VB, do VB as the C# people have the skill to translate more often than vice-versa.

Friday, April 27, 2007 4:23 PM by Mike Schinkel

# re: Feedback Request: What language do you use to write Cmdlets?

Wow.. there's a huge C# following here, so I need to chime in.  VB.NET VB.NET VB.NET!!!  Our entire company is standardized on coding in VB.NET and i wouldn't have it any other way!  VB.NET!

:-)

No offense to the C sharpees - C# is great (I don't get into language religous wars because I feel that each langauge has its own advantages and disadvantages).  I just like VB.NET, personally.

Tuesday, May 01, 2007 9:10 AM by Timothy

# re: Feedback Request: What language do you use to write Cmdlets?

I only use C# for cmdlets. But I suggest VB.net as second language as nearly every C++ User can at least read C#. In my experience this is defintively not true for the typical VB programmer.

Friday, May 04, 2007 4:03 AM by Georg Begerow

# re: Feedback Request: What language do you use to write Cmdlets?

I'm looking into developing a tutorial/course which will help VB scripters and VB.NET programmers write VB.NET cmdlets.  Afterall the Cmdlet class is one which doesn't care which language is used and since these folks are either VB scripters/programmers or new to scripting all all together IMHO the VB path would be a logical way to go.

Thursday, June 07, 2007 4:16 PM by Bob O'Neill

# re: Feedback Request: What language do you use to write Cmdlets?

Never wrote a cmdlet yet - but I will have to do in the future.

Doing that in Ironpython would be nice.

Saturday, September 22, 2007 3:21 AM by ThSchwarz

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker