Script file 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"
When executing this via
powershell -OutputFormat XML -ExecutionPolicy bypass -File c:\chgpwd.ps1 'myuser' 'a' 'b' 2>&1 > C:\out.xml
Note: the user exists but its new password (b) does not match the password policy
the output file (C:\out.xml) won't contain any xml, but the xml will be shown in the console out.
For now I only get the content (out.xml)
powershell : Exception calling "ChangePassword" with "2" argument(s): "The password does not meet the password policy requirements. Check the minimum password length, password complexity and password history requirements. " At line:1 char:1 + powershell -OutputFormat XML -ExecutionPolicy bypass -File C:\chgpwd.ps1 ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo> > : NotSpecified: (:) [chgpwd.ps1], MethodInvocationException + FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI,chgpwd.ps1.ps1
Is there a way I get the xml ouput in the file?