October 22, 2015 at 7:40 am #31171
I decided to begin learning C# – I'm not a developer by trade, but I enjoy "coding" in PowerShell and making apps with it (I can imagine how hilarious our software development department would find that statement) so I wanted to explore programming and in turn, making powershell. I have made PowerShell modules with PowerShell, and I want to try making some Powershell Modules in C#.
I wanted to have a nosey around the PowerShell folder, and see how Jeffrey Snover and the team have done it, but obviously everything is compiled. So, I wanted to know if the PowerShell source code is available anyway?
I had another question.
I have made GUI's in PowerShell, one of my packages is about 5,000 lines... which in PowerShell is a lot in my opinion! Tab controls, Progress bars etc, however, it's hard to develop it into much more, as Powershell is a single thread process. A Powershell studio trial helped me get a few of the basics in place, but I wanted to find out if there's a way I could incorporate a C# front end, so I could have an interactive application while processes run, while still using my PowerShell code?
I can imagine that if I was to try rewriting all the functional code in the background in C#, it wouldn't be done until 2020!
Really long post, and waffled a bit, but I'd love to see people's thoughts and knowledge on this 🙂
October 22, 2015 at 7:44 am #31173
PowerShell itself is not open-source, but you can easily decompile .NET DLLs into fairly readable C# code using ILSpy, dotPeek, or Reflector. (The first two are free.)
There's also an SDK for PowerShell with some sample cmdlets and such. I don't think it's been updated in quite a while, but compiled cmdlets haven't changed all that much anyway. A lot of it will look very familiar if you've been writing Advanced Functions in PowerShell. (Same Parameter attributes on class properties, something very similar to CmdletBinding(), etc.)
October 22, 2015 at 8:25 am #31178
I'd say if your goal is to build a robust GUI, then C# is a better approach than PowerShell. You can still use PowerShell code from within C# – PowerShell is just a class that you instantiate and ask to run commands. That's exactly how the Exchange Management Console is built, and how the Active Directory Administration Center is written.
October 22, 2015 at 10:48 am #31192
Thanks for that Dave, I'll check it out.
Don, do you know if you can use Powershell, like for like in C#? I use variables for storing all kinds of stuff in PowerShell, including scriptblocks. Am I right in thinking I'm going to have to follow C# syntax? In which case I think I'll need more practise first, but thanks for letting me know.
You must be logged in to reply to this topic.