In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces Html+JS+PowerShell how to create a Web version of AD management system, the article is very detailed, has a certain reference value, interested friends must read it!
Use Flask to call Powershell API to achieve the operation and maintenance management system.
In fact, the principle is the same, mainly using the Django/Flask framework, Bootstrap as the front end, and then the background python calls PowerShell API to achieve the query.
But there are both powershell and python backstage, which annoys me very much. I want to use only PowerShell, so I have the following twists and turns.
Go to Demo first.
The front-end page is a simple html. In order to look good, the bootstrap framework is used.
Bootstrap-table is used to display the queried data through tables, as well as export, sorting, paging and other functions.
Event control: jquery,ajax
In the background is the API realized by PowerShell, and there are many on the Internet. I tried the module of HttpListener mentioned in Douzi classmate's blog, and there is no problem with a web framework made by Microsoft employees. PowerShell's Web framework should be all right.
1. Execute PowerShell in the background
Import-Module C:\ users\ yuan.li\ Documents\ GitHub\ Powershell\ HTTPListener.psm1 start-httplistener-verb-Auth None-port 8888
Note: I have made some changes to the HTTPListener.psm1 content to avoid cross-domain restrictions.
# region Cross-domain $response.AddHeader ("Access-Control-Allow-Origin", "*"); $response.AddHeader ("Access-Control-Allow-Headers", "Authentication"); $response.AppendHeader ("Access-Control-Allow-Headers", "Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With"); # endregion Cross-Domain
I don't know much about this piece. I found it on the Internet and pasted it directly, but it did work.
two。 Without the python and flask/django framework, all controls are implemented in JS.
First, use GetURL () to concatenate a url called by powershell
Var $pswebpai = "http://10.128.9.36:8888/?command="// build Webapi URLfunction GetURL (option) {/ / switch URL switch (option) {case" mail ": var $cmdlet =" Get-ADUser-Filter * | select Name,SamAccountName,UserPrincipalName | Where-Object {$_. UserPrincipalName-ne $null} "break Case "computer": var $cmdlet = "Get-ADComputer-Filter *-Property name,DNSHostName,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion" break;} var $url = $pswebpai + $cmdlet / / alert ($url) return $url}
Then, use ajax to implement asynchronous execution
/ / execute $QueryButton.click (function () {/ / get the drop-down menu value var option = $("# myselect") .val (); var $url = GetURL (option) when the query button is clicked Ajax ({url: $url, dataType: 'json', contentType:' application/json', charset: 'UTF-8', success: function (result) {console.log ("Success"); / / console.log (result); CommonTableInit (option, result) / / function to initialize the table}, error: function (result) {alert ("error!");}});})
Such a Web query function is implemented. And there is no need to install the python,flask\ django framework, deployment is also very simple, just hang an address. (the flask version tried to deploy under IIS, but failed-- ~)
The function of adding, deleting, changing and searching can also be expanded in the future.
At present, the only problem is that sometimes HTTPListener query will report an error to exit, it is estimated that a more robust PowerShell Web framework will be fine.
Other ideas:
1. It is completely implemented in the PowerShell Web framework.
2.dotNet Core Web application, generate a self-hosted console application in exe format, and double-click directly to execute it. (WebAPI,C# calls powershell)
* * Link:
Http://down.51cto.com/data/2441697
Cross-domain has never been understood. With jsonp, the returned json object can be seen in the response of debug, but console.log (returned json object); if so, no returned json object data can be seen, and the callback function of ajax does not receive the json object, so it feels as if it was directly received by the browser. It's the same problem with several powershell WebAPI changes. There is also data for direct access to powershell webapi.
The above is all the contents of the article "how to build a Web version of AD management system for Html+JS+PowerShell". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.