I am trying to trigger a ps1 script in remote windows 2016 web server via http get request. This is the code i am trying.
Tried with GET and POST request and receive http 200 status code each time. However powershell script is not getting triggered. Windows server settings is getting checked alongside however wanted to check here if this code looks fine and workavble solution
Tried with GET and POST request and receive http 200 status code each time. However powershell script is not getting triggered. Windows server settings is getting checked alongside however wanted to check here if this code looks fine and workavble solution
def trigger_remote_powershell(remote_url, script_path): # Prepare the PowerShell command to execute on the remote machine powershell_command = f"Invoke-Expression (New-Object Net.WebClient).DownloadString('{remote_url}/{script_path}');" # Send the HTTP POST request payload = {'command': powershell_command} response = requests.post('http://your_remote_machine_url', data=payload) # Check the response if response.status_code == 200: print('PowerShell script triggered successfully.') else: print(f'Error triggering PowerShell script. Status code: {response.status_code}') if __name__ == "__main__": # Replace the placeholders with your actual values remote_url = 'http://your_remote_machine_url' script_path = 'path/to/your/script.ps1' trigger_remote_powershell(remote_url, script_path)
Larz60+ write Jan-25-2024, 11:14 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Code has been modified for you this time. Please use BBCode tags on future posts.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Code has been modified for you this time. Please use BBCode tags on future posts.