【发布时间】:2016-06-01 10:32:11
【问题描述】:
脚本文件c:/chgpwd.ps1
Param(
[parameter(Mandatory=$true)]
[string] $user,
[parameter(Mandatory=$true)]
[string] $oldPass,
[parameter(Mandatory=$true)]
[string] $newPass
)
write-host "before"
$Computername = $env:COMPUTERNAME
([adsi]"WinNT://$Computername/$user").ChangePassword("$oldPass", "$newPass")
write-host "after"
当通过
执行时powershell -OutputFormat XML -ExecutionPolicy bypass -File c:\chgpwd.ps1 'myuser' 'a' 'b' 2>&1 > C:\out.xml
注意:用户存在但其新密码(b)与密码策略不匹配
输出文件 (C:\out.xml) 将不包含任何 xml,但 xml 将显示在控制台输出中。
目前我只获取内容(out.xml)
powershell:使用“2”参数调用“ChangePassword”的异常:“密码不符合密码策略 要求。检查最小密码长度、密码复杂性和密码历史要求。 " 在行:1 字符:1 + powershell -OutputFormat XML -ExecutionPolicy 绕过 -File C:\chgpwd.ps1 ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo> > : NotSpecified: (:) [chgpwd.ps1], MethodInvocationException + FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI,chgpwd.ps1.ps1
有没有办法在文件中获取 xml 输出?
【问题讨论】:
-
你期望什么输出?为什么需要 xml?
-
我本来希望渲染到控制台的 xml 出现在输出文件中(如果通过管道传输)。对于解析错误消息xml会更好。
标签: xml powershell output command-line-interface