C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,266 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi Guys,
I'm trying to create a PS Cmdlet in C# that will Creaet a PS-Session (Runspace?) and output the Ps-Session to the user.
i am able to establish a connection in c# but i can't figure out how to pass it to PowerShell? (i assume i need to output a ps session?)
PSCredential creds = new PSCredential(Uname, Pass);
WSManConnectionInfo connectionInfo = new WSManConnectionInfo();
connectionInfo.ComputerName = IP;
connectionInfo.Port = Port;
connectionInfo.Credential = creds;
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Credssp;
Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo);
runspace.Open();
You could start here: using-c-to-create-powershell-cmdlets-the-basics
create-powershell-cmdlets-in-c-sharp-pipeline-chaining
There are more if you search for "create powershell cmdlet using c#"