The Evan children's shoes in QQ group share a very interesting blog http://note.youdao.com/noteshare?id=a60709c00fe88cd09155a2ef50815281 probably how to use flask call A maintenance management system implemented by the Powershell API.
The beans are drawn with a gourd and a simple interface is successfully implemented with Django. Use the bootstrap template to get a front-end page, the Django framework, and then invoke the PowerShell API to implement the query in the background.
Here is a simple demo, enter the ad group, show group members
650) this.width=650; "src=" Https://s1.51cto.com/oss/201711/08/78c29eb3691e6278c898e30de8ff3b02.png "title=" Capture.png "alt=" 78c29eb3691e6278c898e30de8ff3b02.png "/>
Django has nothing to say, the basic MTV framework process, the main more interesting is the PowerShell API module. On-line HttpListener module can be downloaded, QQ Group of children's shoes made some changes, removed a verification function, if there is a need, you can manually add a function in. I'm here to figure out how easy it is to use the verified version directly.
After the module has been downloaded, it can be executed, he provides a restful interface to execute PowerShell commands, a direct HTTP GET request corresponding interface, and return the results in JSON format
Import-module C:\users\yuan.li\Documents\GitHub\Powershell\HTTPListener.psm1start-httplistener-verb-Auth None
Test it:
Browser
650) this.width=650; "src=" Https://s1.51cto.com/oss/201711/08/50e5bcbc7fd0ffd4697128c38d85cc05.png "style=" float: none; "title=" 1.PNG "alt=" 50e5bcbc7fd0ffd4697128c38d85cc05.png "/>
Python
650) this.width=650; "src=" Https://s1.51cto.com/oss/201711/08/c223bcd2dd23639ed0880f96e3fcbee5.png "style=" float: none; "title=" 2.PNG "alt=" C223bcd2dd23639ed0880f96e3fcbee5.png "/>
It is worth mentioning that where the specific PowerShell commands are placed, we can set them in two places. One is directly inside the URI command= back input, simple commands do not matter, but if the command is very complex and long, here is not very suitable;
Another way is to write a function directly inside the HttpListener module file, so that it is loaded into memory together. command= directly following the function name and parameters on the line.
For example:
function Search-adgroupmemeber ($group) {get-adgroupmember $group | select name, samaccountname,distinguishedname}
Then I call directly
Http://localhost:8888/?command=search-adgroupmemeber ' Domain Admins '
Show results
650) this.width=650; "Src=" Https://s1.51cto.com/oss/201711/08/e80f700b86b5cef3b1d3821326181bfb.png-wh_500x0-wm_3 -wmp_4-s_3978874792.png "title=" 3.PNG "alt=" E80f700b86b5cef3b1d3821326181bfb.png-wh_ "/>
Okay, basically work, so you can get a look at Django.
url.py Routing
URL (r ' ^powershell ', Views.powershell),
views.py View Functions
Import Requestsdef PowerShell (req): If req.method== "GET": Return render (req, ' powershell.html ') elif Req.metho d== "POST": Name=req. Post.get ("caption") print (name) res=requests.get ("Http://localhost:8888/?command=get-adgroupmember '%s ' | Select name, distinguishedname "%name) print (res) Result=res.json () print (result) return render (req, ' powershell.html ', {' result ': result})
powershell.html template, here I do not use Ajax, is direct form to submit
{% extends ' base.html ' %} {% block css %} <style> .go{ width:20px; border: solid 1px; color: #66512c; display: inline-block; padding: 5px; } .pagination .page{ border: solid 1px; color: #66512c; display: inline-block; padding: 5px; background-color: #d6dade; margin: 5px; } . pagination .page.active{ Background-color: black; color: white; } . hide{ display: none; } .shade{ position: fixed; top: 0; right: 0; left: 0; bottom: 0; background: black; opacity: 0.6; z-index: 100; } . add-modal,.edit-modal{ position: fixed; height: 300px; width: 400px; top:100px; left: 50%; z-index: 101; border: 1px solid red; background: white; margin-left: -200px; } .group{ margin-left: 20px; margin-bottom: 15px; } </style>{% endblock %}{% block content %}
Such a query effect is made.
This article is from the "Mapo Tofu" blog, please be sure to keep this source http://beanxyz.blog.51cto.com/5570417/1979809
django+ PowerShell Management AD System