1

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?

2
  • What output do you expect? Why do you need xml? Commented Jun 1, 2016 at 10:48
  • I would have expected the xml which is rendered to the console out to be in the out file (if piped). For parsing the error message xml would be better. Commented Jun 1, 2016 at 10:55

1 Answer 1

0

i have not used the -OutputFormat switch before, but you may be able to use export-clixml

try {
    1/0
} catch {
    $_ | Export-Clixml C:\temp\text.xml
    start C:\temp\text.xml
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the quick answer: I tried this and it works fine, but in case of a syntax error in the script this won't help or if a required parameter is missing or if it cannot find the file. Especially in my case the script comes from third party.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.