公共语言运行时检测到无效程序运行powershell

时间:2018-10-12 05:00:15

标签: c# powershell console-application

执行代码时出现此错误。我的powershell版本是5.1

这里是我的代码。感谢您的帮助。

static void Main(string[] args)
{
    var script = @" 
        $ous = 'OU=test,DC=test,DC=local' $When = ((Get-Date).AddDays(-20)).Date $ous | ForEach { Get-ADUser -Filter {whenCreated -ge $When} -Properties whenCreated,* -SearchBase $_ }";
    var powerShell = PowerShell.Create();
    powerShell.AddScript(script);
    foreach (var Office in powerShell.Invoke())
    {
        Console.WriteLine(Office);
    }
}

enter image description here

0 个答案:

没有答案