Chris
 New Member Posts:5

 |
| 28 Jun 2009 09:30 PM |
|
Hi Guys I want to know if it is possible to create a cmdlet in any language other than C# or VB. Is it possible to develop in powershell itself? Thanks Chris |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
|
Marco Shaw (MVP)
 Veteran Member Posts:1641

 |
| 29 Jun 2009 08:46 AM |
|
Can you be more specific on what you might want to do? You're hoping to do something in C, for example? Apparently you can do .NET programming in C, but I'm not experience enough to know if this can be extended to PowerShell and whether there may be limitations.
|
|
Marco
*Microsoft MVP - Windows PowerShell
https://mvp.support.microsoft.com/profile/Marco.Shaw
*Co-Author - Sams Windows PowerShell Unleashed 2nd Edition
*Blog - http://marcoshaw.blogspot.com |
|
|
Chris
 New Member Posts:5

 |
| 29 Jun 2009 02:47 PM |
|
I want to develop commandlets that would make WMI calls to get some disk management tasks. Since there is a good support for WMI in powershell, I was thinking of doing things in powershell itself. |
|
|
|
|
Marco Shaw (MVP)
 Veteran Member Posts:1641

 |
| 29 Jun 2009 06:04 PM |
|
Well, you have a few options with WMI... You can use the PowerShell API, or make your own direct calls to either WMI via managed code or through COM. For example, Hyper-V is managed completely via a WMI API... |
|
Marco
*Microsoft MVP - Windows PowerShell
https://mvp.support.microsoft.com/profile/Marco.Shaw
*Co-Author - Sams Windows PowerShell Unleashed 2nd Edition
*Blog - http://marcoshaw.blogspot.com |
|
|
Poshoholic PowerShell MVP, Community Director
 Basic Member Posts:110

 |
| 30 Jun 2009 09:20 AM |
|
Chris, Wrapping WMI calls in PowerShell functions (or in advanced functions in v2) is a great practice. Using Marco's Hyper-V example, in the Hyper-V PowerPack for PowerGUI I have written over 30 functions to make working with Hyper-V as easy as working with any well designed cmdlet. Those functions are all visible in PowerGUI so you can feel free to take a look and see how I do that today using v1. Actually, so far I have stuck with my decision to write any extension I write for PowerShell in PowerShell itself. That has helped me learn how the language works and I still take that approach today. So far this has been exclusively using functions in PowerShell v1, and while v1 functions are not quite the same as cmdlets you can do a ton with them and get the same experience as you get when working with cmdlets. I'll be converting those functions over to advanced functions for the next little while and that will make them be a little closer to the cmdlet experience. Plus using functions gives people access to source code, lets them step through it and find and report bugs, etc, making it more of a community effort. I highly recommend it. |
|
Kirk Munro [MVP]
Poshoholic
My blog: http://poshoholic.com
Follow me on Twitter: http://twitter.com/poshoholic |
|
|