Why is all MS docs on topic of Powershell WinForms in C# and not in PS?

Ian L 6 Reputation points
2021-10-22T02:43:40.977+00:00

I understand that WinForms uses the .Net framework.

However having to search many sources to get basic understanding of how a PS Winform object works precisely is a painful process.

For example let's say I'm trying to learn about DataGridView
I search System.Windows.Forms.DataGridView I get the MS docs article great let's open that up oh look all the examples are in C# no idea how to convert that in PS language. There is no screenshots or anything to show what a datagridview.

Then more searching to find examples of PS winform datagridview in use
Then find an example of something similar to what I want to use it for.

Also the listing for ALL the options/properties for this object is at best limited. So this has resulted to using PS ISE then type $DataGridView. and go through each suggested property type listed in ISE suggestions then search for that. Imagine having to repeat this process for learning about each WinForm object.

How do admins go about using this? It does not seem reasonable that you need to know C# and PS scripting languages in order to have a chance at converting C# into PS. For those whom have posted examples of variety of WinForms objects are legends.

There has to be a better way.

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 47,906 Reputation points
    2021-10-25T19:08:31.933+00:00

    I suppose the best answer to the question is that System.Windows.Forms.DataGridView is part of .Net and there's nothing specific to PowerShell there.

    If you're doing enough work in PowerShell and a lot of it is using C# the needs conversion to PowerShell, have a look at PowerShell Pro Tools. The paid version has a converter, but one-to-one conversion in either direction (in any languages) is hardly ever completely satisfactory.

    You can also include C# code directly in a PowerShell script, it that's a help.

    I'd ditch the PowerShell ISE (it's no longer a supported product) and move to either VS Code or Visual Studio.

    As for a complete list of a .Net class's properties any methods, have a look at the web page for that class. You should find a description of the class and beneath that a "Constructors", "Methods", and "Properties" item.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.