I am writing a website in Python Flask with Powershell scripts integrated.
I want to run a Powershell script that uses input from the user via the html page.
But it never reaches the Powershell script.
So in the function cqforward, the Powershell script is running fine. As in the second function cqshowlist the webapp doesn’t reach the Powerschell script after i fill in the inputfield and click on the button?
from flask import Flask, render_template, request, jsonify
import subprocess
import json
app = Flask(__name__)
@app.route('/')
def home():
return render_template('home.html')
@app.route('/Activate Forward',methods=['GET','POST'])
def cqforward():
if request.method == 'POST':
namecq = request.form.get('namecq')
phonenumber = request.form.get('phonenumber')
subprocess.run(["powershell","-File","cqforward.ps1", namecq, phonenumber])
data = {
'namecq': namecq,
'phonenumber' : phonenumber
}
return render_template('cqforward.html', data = {"namecq": namecq, "phonenumber": phonenumber})
return render_template('cqforward.html', data = None)
@app.route('/Show list',methods=['GET','POST'])
def cqshowlist():
if request.method == 'POST':
listcqname = request.form.get('listcqname')
subprocess.run(["powershell","-File","listofcallqueues.ps1", listcqname])
data = {
'listcqname': listcqname
}
return render_template('cqshowlist.html', data = {"listcqname": listcqname})
return render_template('cqshowlist.html', data = None)
@app.route('/Show Holidays')
def holidays():
return render_template('tgholidays.html')
if __name__ == '__main__':
app.run(debug=True)
So the above is the Python start code.
And herunder is the Powershell script:
param(
[string]$listcqname
)
$listnamecqVariable = "CQ-"+ $listcqname + "-*"
Write-Output "Name: $listnamecqVariable"
Connect-MicrosoftTeams
#Get all Call Queues via the CQ-FSECO Security groups
$CallQueues = Get-CsCallQueue -NameFilter {Name -Like $listnamecqVariable}
#Set the csv-file
$Directory = "test.csv"
$DirectoryXlsx = "Test.xlsx"
Set-Content -Path $Directory -Value "Name"
#Go Through the Call queues list
foreach($CQs in $CallQueues)
{
$Name = $CQs.Name
$Name
Add-Content -Path $Directory -Value "$Name"
}
import-Csv -Path $Directory | Export-Excel -Path $DirectoryXlsx -WorksheetName "Sheet1" -AutoSize -BoldTopRow
#import-csv -Path $Directory |Export-Excel -Path $DirectoryXlsx
Write-Output "Finished Running"
As last the webpage has a one field form on it
Printscreen of the webapp page
6