How to Pass PSCredential object from C# code to Powershell Function

Question:

I have a PSCredential Object in C# and want to pass it as parameter for this PowerShell Script

This is the PSCredential Object

This is the Script I want to run in C#

I couldn’t understand the solution which is offered here Pass a Parameter object (PSCredential) inside a ScriptBlock programmatically in C#

EDIT:
This thing is working

But how can I save the Session Info in a variable? I need them for the following commands:

Answer:

I found the solution now. It’s so easy when you know what you do…

Where Credential is the C# PSCredential object

Source:

How to Pass PSCredential object from C# code to Powershell Function by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply