Python Forum
Show powershell errors in flask-wtf web form - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Show powershell errors in flask-wtf web form (/thread-42379.html)

Pages: 1 2


RE: Show powershell errors in flask-wtf web form - robertkwild - Jun-29-2024

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?


RE: Show powershell errors in flask-wtf web form - robertkwild - Jun-29-2024

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 ?


RE: Show powershell errors in flask-wtf web form - robertkwild - Jun-29-2024

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


RE: Show powershell errors in flask-wtf web form - robertkwild - Jun-30-2024

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'



RE: Show powershell errors in flask-wtf web form - robertkwild - Jun-30-2024

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)