Page 1 of 1
Modules for classes
Posted: Tue Jun 04, 2019 1:18 pm
by mgebauer
Hello, I am just starting to learn Powershell Studio after spending most of my time in Visual Studio and C#.
Right now I'm trying to convert a program over so I'm not the only support person anymore and it relies pretty heavily on classes.
In Visual Studio I've always made class files and put all the code for the class into that file to keep the main file somewhat easier to work with. Does PS Studio work in the same way, or should I be throwing all the classes right into the main psf file?
Re: Modules for classes
Posted: Tue Jun 04, 2019 2:29 pm
by Olga_B
Hello,
In PowereShell Studio you can create Project and work with files.
For more info check Product Manual Chapter 8 - Projects
Also check new Project features in this article
https://www.sapien.com/blog/2018/08/14/ ... e-support/
Re: Modules for classes
Posted: Tue Jun 04, 2019 2:54 pm
by jvierra
The use of classes in PowerShell is mostly for support for DSC. Classes can be used as needed. The choice of classes as an element of your design is optional. Classes can be declared in any file or module. It all depends on what you are trying to accomplish.
I recommend against attempting to directly convert C# or VB classes to PowerShell. PS classes are not capable of doing this directly as they do not support most features of compiled programs.
When I need a C# class in PowerShell I usually use Add-Type to compile the code into PS. I also use Visual Studio to compile the class into an assembly and then just load and use them from PS.
See the help for "Add-Type".
PowerShell Studio is an IDE that is similar to VS but PowerShell is not a compiled language. PSS does not directly address design of a packaged script but, like VS, it does provide a robust and extensive set of tools for implementing your design. The approach and limits to that design are set by PowerShell and not by PSS.
DO not think of PS as an application development tool. It is an administrative scripting language that is not designed to create applications. PSS creates "packaged script" and not applications. You cannot directly translate Visual Studio projects into PowerShell projects. To assume that you can will only cause issues with what you may be trying to accomplish.
Re: Modules for classes
Posted: Tue Jun 04, 2019 6:02 pm
by mgebauer
Thanks, it's quite possible that my app is not nearly as complex as you are thinking.
It's a tool for Field Services to create autologon users in AD, and essentially do role base computers. So each computer type has a role (a few AD groups that make it behave a certain way when GPOs are applied) rolled up to make it a build.
FS picks a build from the list and off it goes using the templates its told. The templates in C# were all classes with a few attributes, some having a list of classes as an attribute (for AD groups for the user and for the PC)
The ideas I believe translate well, the guts I know are different, but I believe Powershell has all the functionality needed, it's just a matter of organizing it in an efficient way.
I'm really trying to make anything I do supportable by someone else who knows powershell or who can at least stumble through it, because once you make yourself irreplaceable that way, you also make it so you can't do anything else or have a good vacation, because you are too needed supporting aging things to do anything new.
Re: Modules for classes
Posted: Tue Jun 04, 2019 11:45 pm
by jvierra
PowerShell cannot run multi-threaded forms. PS has only one thread. This also means that creating complex UIs can be impossible. As long as you only need basic Windows Dialogs windows then it is a good way to build simple tools.
I definitely agree that code should be maintainable by other than the programmer. I have designed and developed many systems and always delivered a system that I hoped would not need me after the initial shakedown. This has been the case most of the time.
Most of what you describe is managed by AD and requires little in the way of code. PowerShell Studio is excellent at building UIs as long as you have a good understanding of how to design and develop with WinForms. Sapien has a good amount of technical posts covering ma y aspects of forms design and there are many videos.
Most important is that WInForms development with PowerShell requires a very good understanding of PowerShell. I cannot stress this enough as lack of PowerShell skills will make forms development very challenging.
PowerShell Studio is a very good tool for learning PowerShell and advanced PowerShell as well as WinForms. It has numerous features which aid in coding. This allows the user to learn PowerShell in a rich environment with built in links to online documentation.
PSS also allows for versioning and code repositories for use with teams and for code maintenance.
PSS and PowerShell can easily do what you ask as long as you understand the limitations that a scripting environment creates versus compiled languages.