Для вызова файла сценария powershell (example.ps1) из C #

Я попытался запустить скрипт localwindows.ps1 из C #, используя следующий код:

               PSCredential credential = new PSCredential(userName, securePassword);
                WSManConnectionInfo connectionInfo = new WSManConnectionInfo(false, "machineName", 5985, "/wsman", shellUri, credential);
                using (Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo))
                {

                    runspace.Open();
                    String file = "C:\\localwindows.ps1";
                    Pipeline pipeline = runspace.CreatePipeline();
                    pipeline.Commands.AddScript(file);
                    pipeline.Commands.Add("Out-String");
                    Collection<PSObject> results = pipeline.Invoke();
                }

Но получим исключение: «Термин« C: \ localwindows.ps1 »не распознается как имя командлета, функции, файла сценария или работоспособной программы.

Поэтому я попробовал следующее:

PSCredential credential = new PSCredential(userName, securePassword);
WSManConnectionInfo connectionInfo = new WSManConnectionInfo(false, "machineName", 5985, "/wsman", shellUri, credential);
using (Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo))
{

    runspace.Open();

    using (PowerShell powershell = PowerShell.Create())
    {
        powershell.Runspace = runspace;           

        PSCommand new1 = new PSCommand();
        String machinename = "machinename";
        String file = "C:\\localwindows.ps1";
        new1.AddCommand("Invoke-Command");
        new1.AddParameter("computername", machinename);
        new1.AddParameter("filepath", file);         


        powershell.Commands = new1;
        Console.WriteLine(powershell.Commands.ToString());
        Collection<PSObject> results = powershell.Invoke();

     }

Я получаю сообщение об ошибке: «Не удается найти путь« C: \ localwindows.ps1 », поскольку он не существует».

Но с помощью команды 'Invoke-Command -ComputerName "machineName" -filepath C: \ localwindows.ps1' из powershell на локальной машине была создана новая учетная запись на удаленной машине.

Как вызвать скрипт localwindows.ps1 из C #? Как выполнить команду 'Invoke-Command -ComputerName "machineName" -pilepath C: \ localwindows.ps1' через C #?

Сценарий localwindows.ps1 является

$comp = [adsi]“WinNT://machinename,computer”
$user = $comp.Create(“User”, "account3")
$user.SetPassword(“change,password.10")
$user.SetInfo()