Run Powershell commands inside Winform C# with another users crfedential


New member
Sep 8, 2016
Programming Experience
When I click the view button it executes the Powershell code successfully and displays the results in 3 different textboxes. This is working as should.

But I need to run this with another user credential and this should happen when I click the command button.

We are not going to get access to that remote computer with our current user and password.. I need a workaround for this.

1. I do not want a prompt for entering the user name and password.
2. I want this to be transparent.

I have looked and try solutions from other sites but these where for running in Powershell and not in Visual Studio C# Winforms.

Any assistance is appreciated.

                //string Test = textBoxScript.Text;

                //Returns all the Process running
                txtTaskList.Text = RunScript("Get-Process -ComputerName pcname | Where-Object {$_.responding -eq $True} | Format-Table -AutoSize ProcessName, Responding, CPU");

                //Returns all Process that are not running
                txtTaskNotResponding.Text = RunScript("Get-Process -ComputerName  pcname | Where-Object {$_.responding -eq $false} | Format-Table -AutoSize ProcessName, Responding, CPU | Sort-Object ProcessName -Descending");

                //Returns the Eventlog in application log with errors
                txtEventLogError.Text = RunScript("Get-WinEvent -FilterHashtable @{logname= 'Windows PowerShell'} -MaxEvents 100 -ComputerName pcname | Where-Object LevelDisplayName -Like 'Information' | Sort-Object TIMECREATED -Descending");

            catch (Exception error)
                txtTaskList.Text += String.Format("\r\nError in script : {0}\r\n", error.Message);
                txtTaskNotResponding.Text += String.Format("\r\nError in script : {0}\r\n", error.Message);
                txtEventLogError.Text += String.Format("\r\nError in script : {0}\r\n", error.Message);
Top Bottom