Python Forum
Show powershell errors in flask-wtf web form
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Show powershell errors in flask-wtf web form
#11
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?
Reply
#12
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 ?
Reply
#13
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
Reply
#14
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'
Reply
#15
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Cant get powershell script to run with subprocess robertkwild 2 151 Jun-27-2024, 01:23 PM
Last Post: robertkwild
  Running powershell command in flask wtf form robertkwild 10 336 Jun-27-2024, 09:49 AM
Last Post: robertkwild
  Passing web form to powershell robertkwild 1 280 Jun-14-2024, 10:16 AM
Last Post: Akshiya
  using split in my flask wtf form robertkwild 1 193 Jun-11-2024, 05:19 PM
Last Post: deanhystad
  making a form purely with flask-wtf robertkwild 15 847 Jun-01-2024, 11:53 AM
Last Post: robertkwild
  using PowerShell from Python script for mounting shares tester_V 8 854 Mar-12-2024, 06:26 PM
Last Post: tester_V
  PowerShell & Python deep_logic 2 850 Jun-06-2023, 06:34 AM
Last Post: buran
  PIL Image im.show() no show! Pedroski55 2 1,091 Sep-12-2022, 10:19 PM
Last Post: Pedroski55
  How to write a part of powershell command as a variable? ilknurg 2 1,240 Jul-26-2022, 11:31 AM
Last Post: ilknurg
  PIL Image im.show() no show! Pedroski55 6 5,488 Feb-08-2022, 06:32 AM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020