我在PowerShell中有脚本:
Get-ADUser $Login -Properties msDS-UserPasswordExpiryTimeComputed |
select -expand msDS-UserPasswordExpiryTimeComputed
我正在尝试将它导入到C# (WPF)中,但是结果/结果2总是0。PowerShell脚本运行良好,并返回信息。
using (PowerShell PS = PowerShell.Create())
{
PS.AddScript("Get - ADUser");
PS.AddParameter("Identity", TextBox_UserLoginIn.Text);
PS.AddParameter("Properties", "msDS-User-Account-Control-Computed");
PS.AddStatement();
PS.AddCommand("Select");
PS.AddParameter("-expand", "msDS-UserPasswordExpiryTimeComputed");
var result = PS.Invoke();
long result2 = long.Parse(result.ToString());
DateTime psdata = DateTime.FromFileTimeUtc(result2);
_MetroWindow.TextBox_UserPassExpire.Text = psdata.ToString();
}
也尝试使用import activedirectory,但结果是相同的:
PS.AddCommand("Import-Module").AddParameter("Name", "activedirectory");
PS.AddCommand("Get - ADUser").AddParameter("Identity", TextBox_UserLoginIn.Text);
PS.AddParameter("Properties", "msDS-User-Account-Control-Computed");
PS.AddStatement();
PS.AddParameter("-expand", "msDS-UserPasswordExpiryTimeComputed");
编辑:试图换:
PS.AddScript("import-module activedirectory");
PS.AddScript("Get-ADUser -Identity " + TextBox_UserLoginIn.Text + " -Properties msDS-UserPasswordExpiryTimeComputed | select -expand msDS-UserPasswordExpiryTimeComputed");
其结果是:
result Count = 1
result2 0
也许有一种方法可以接收从"DirectoryEntry“或"PrincipalContext”计算出来的msDS用户帐户-控制?我使用这两个类从AD获取信息,但我无法访问这个。
发布于 2018-07-27 10:08:10
这样做是可行的:
PS.AddScript("Get-ADUser " + TextBox_UserLoginIn.Text + " -Properties msDS-UserPasswordExpiryTimeComputed | Select -Expand \"msDS-UserPasswordExpiryTimeComputed\"");
发布于 2018-07-25 12:44:34
我认为您为您所寻求的属性的参数做了一个错误的输入:
PS.AddParameter("Properties", "msDS-User-Account-Control-Computed");
应该是
PS.AddParameter("Properties", "msDS-UserPasswordExpiryTimeComputed");
我猜
编辑
您正在更新/试用这两个版本中的哪一个?
我认为完整的事情应该是
using (PowerShell PS = PowerShell.Create())
{
PS.AddCommand("Import-Module").AddParameter("Name", "activedirectory");
PS.AddScript("Get-ADUser");
PS.AddParameter("Identity", TextBox_UserLoginIn.Text);
PS.AddParameter("Properties", "msDS-UserPasswordExpiryTimeComputed");
PS.AddStatement();
PS.AddCommand("Select");
PS.AddParameter("-expand", "msDS-UserPasswordExpiryTimeComputed");
var result = PS.Invoke();
long result2 = long.Parse(result.ToString());
DateTime psdata = DateTime.FromFileTimeUtc(result2);
_MetroWindow.TextBox_UserPassExpire.Text = psdata.ToString();
}
https://stackoverflow.com/questions/51519085
复制相似问题