Welcome to FoxLearn
In this tutorial, I'll show you how to run PowerShell command in Windows Forms Application using Visual Basic .NET
Open your form designer, then drag TextBox, Label and Button controls from the visual studio toolbox to your winform.
We will design a simple UI allows you to run the PowerShell command in Windows Forms Application.
You need to install the System.Management.Automation library from the Manage Nuget Packages to your project
The System.Management.Automation library is an opensource that allows you to run PowerShell commands in Visual Basic .NET
PowerShell is a task automation and configuration management framework from Microsoft
and it consists of a command-line shell and associated scripting language.
We will create a RunScript method allows you to run the PowerShell command.
A runspace is the operating environment for the commands that are invoked by a host application
This environment includes the commands and data that are currently present, and any language restrictions that currently apply
Host applications can use the default runspace that is provided by Windows PowerShell
which includes all available core commands, or create a custom runspace that includes only a subset of the available commands.
After creating a runspace, We will add Windows PowerShell commands and scripts to a pipeline
and then invoke the pipeline synchronously or asynchronously.
You can run an existing script by calling the AddScript method.
Finally, You can use the StringBuilder class to add data, then convert to a string.
Thank you for watching this video and don't forget to subscribe to my channel