Python Forum

Full Version: Show powershell errors in flask-wtf web form
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
so is "capture output" to get the stderr and stdout results and return code just to get the return code ie 0 or 1 or 2

and "check" to either do something if success or do another if failed?

so whats the difference Dean between try/except or if/else?
ok got a problem, the "return code" for Set-ADAccountPassword is either "0" or "1"

there not different as i was hoping for as theres more than one fail ie password incorrect or your last password cant re use

least stderr i get the different errors, can i use that ?
ok i stand corrected the stderr is the same so i think it wont work regardless as the error for anything ie im entering in my old password incorrectly new password cant match previous old passwords is all the same error

The password does not meet the length, complexity, or history requirement of the domain
what am i doing wrong here Dean please

if request.method == 'POST' and form.validate():
            result = subprocess.run(f'powershell.exe $cred = Import-CliXml -Path C:\\python\\cred.xml; Set-ADAccountPassword -Credential $cred -Identity {form.un.data} -OldPassword (ConvertTo-SecureString -AsPlainText {form.op.data} -Force) -NewPassword (ConvertTo-SecureString -AsPlainText {form.cnp.data} -Force) -Server {form.dom.data}', capture_output=True, text=True, shell=False)
            return '<h1>The username is {}. The old password is {}. the new password is {}. changing for domain {}'.format(form.un.data, form.op.data, form.cnp.data, form.dom.data)
        if "The specified network password is not correct" in stderr_string():
        return 'your old/current password is incorrect, please click back and try again'
ok this works guys, can you please check and let me know

if request.method == 'POST' and form.validate():
        result = subprocess.run(f'powershell.exe $cred = Import-CliXml -Path C:\\python\\cred.xml; Set-ADAccountPassword -Credential $cred -Identity {form.un.data} -OldPassword (ConvertTo-SecureString -AsPlainText {form.op.data} -Force) -NewPassword (ConvertTo-SecureString -AsPlainText {form.cnp.data} -Force) -Server {form.dom.data}', capture_output=True, text=True, shell=False)
        if 'The specified network password is not correct' in result.stderr:
            return 'your old/current password is incorrect, please click back and try again'
        if 'The password does not meet the length, complexity, or history requirement of the domain' in result.stderr:
            return 'cant re-use one of your old passwords or cant change password as still less than one day old'
        if result.returncode == 0:
            return '<h1>The username is {}. The old password is {}. the new password is {}. changing for domain {}'.format(form.un.data, form.op.data, form.cnp.data, form.dom.data)
    return render_template('password.html', form=form)
Pages: 1 2