我遇到了一个奇怪的问题,也许有人可以帮助我.
我试图在使用Windows 10的计算机上使用C#从Active Directory用户检索终端服务属性.我这样做是通过在我的应用程序中运行PowerShell脚本,如下所示:
var script = $@"Import-module ActiveDirectory
$user=[ADSI]""LDAP://192.111.222.33:389/CN=SomePerson,DC=Domain,DC=local""
$user.psbase.Username = ""administrator""
$user.psbase.Password = ""adminPassword""
$user.psbase.invokeget(""TerminalServicesProfilePath"")";
using (var runspace = RunspaceFactory.CreateRunspace())
{
runspace.Open();
using (var pipeline = runspace.CreatePipeline())
{
pipeline.Commands.AddScript(script);
var test = pipeline.Invoke();
Console.WriteLine("Success: ");
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
我得到这个例外:
System.Management.Automation.MethodInvocationException:'带有"1"参数的异常调用"InvokeGet":"未知名称.(HRESULT异常:0x80020006(DISP_E_UNKNOWNNAME))"'
当我在使用Windows Server 2012作为操作系统的计算机上运行Visual Studio 2015中的上述代码时,它工作正常!我确保我的Windows 10机器也安装了RSAT.
$user = [ADSI]"LDAP://192.111.222.33:389/CN=SomePerson,DC=Domain,DC=local"
$user.psbase.Username = "administrator"
$user.psbase.Password = "adminPassword"
Write-Output "Terminal Services profile path:"
Write-Output $user.psbase.invokeget("TerminalServicesProfilePath")
Run Code Online (Sandbox Code Playgroud)
以下是PowerShell的输出:
我也尝试在Visual Studio的PowerShell交互式窗口中运行该脚本,这也是有效的.这是截图和输出:(
识别信息审查)
但是,当我使用这些属性名称运行脚本时,我没有收到正确的信息.它们似乎不是同一个属性.以下是我的用户在Active …