我是 Powershell 新手,但不熟悉编程
我创建了一个表单来监控网络服务器的可用性
我用的是Primalforms 2011,相当不错。
该脚本运行良好,结果符合预期。
下一步是以 10 分钟的间隔持续检查网络服务器。
我的问题是如何从 Powershell 表单中实现此目的。
我可以创建另一个脚本来每 10 分钟调用该脚本,但这不是一个聪明的方法(恕我直言)。
我想要的是每 10 分钟从表单中调用一次 Webcheck 函数,检查页面并相应地更新状态。
是否有一些关于 Poweshell 表单内部工作原理的文档,或者是否是反复试验?
这本身是可能的。
I am new in Powershell but not to programing
I have created a form to monitor web server availablility
I used Primalforms 2011 which is quite good.
The script works fine and the result is as expected.
The next step is to continuously check the webservers at a 10 minute interval.
My question is how can I achieve this from within yhe Powershell form.
I can create a another script to call the script every 10 minutes but that is not a smart way(IMHO).
What I would like is to call the Webcheck function every 10 minutes from withing the form, check the pages and update the status accodingly.
Is there some documentation on how the Poweshell form intenals work or is it trial and error?
It is per se possible.
发布评论
评论(2)
查看 PSH2 中的异步事件处理:
Register-ObjectEvent< 的帮助/code>
包含一个带有计时器的示例。
(网络搜索也许能够找到 PowerShell + GUI + Timer 的更完整示例。例如 http://www.sapien.com/blog/2011/08/09/primalforms-2011-spotlight-on-the-timer-control/)
Look at the asynchronous event handling in PSH2: the help for
Register-ObjectEvent
includes an example with a timer.(A web search might be able to find a fuller example of PowerShell + GUI + Timer. Eg. http://www.sapien.com/blog/2011/08/09/primalforms-2011-spotlight-on-the-timer-control/)
本身不是答案,但我个人更喜欢监控解决方案,而不是在机器上运行的 GUI。当然,这取决于您所监视的内容的要求\SLA,并且仅 GUI 的解决方案具有许多优点。
让某种形式的调度软件运行一个更新数据文件或数据库的脚本,然后进行 GUI 读取,这将是我的首选方式。
您可以使用 Windows 计划任务在简单的级别上完成此操作。如果您不想使用数据库,您可以使用 Export\Import-CliXML 来非常快速、轻松地存储数据。让 GUI 每 X 分钟检查一次新的\更新的文件,如果是新的则加载它。
我在使用 Sapien 时所做的事情是在 PowerShell 模块中编写所有功能代码,并让 GUI 调用模块 cmdlet。我喜欢保持显示与功能不同的想法 - 就像 Web 开发中的 MVC。如果您想重用脚本中的函数,它非常有用。
Not an answer per se but personally I prefer a monitoring solution to be more than a GUI running on a machine. Of course it depends on the requirements\SLA of what you are monitoring and a GUI only solution has many advantages.
Having some form of scheduling software running a script that updates a datafile or database and then have a GUI read that would be my preferred way.
You could do it on a simple level with windows scheduled tasks. If you don't want to use a database you could use Export\Import-CliXML for very quick and easy data storage. Have the GUI check for a new\updated file every X minute(s) and load it if it's new.
Something I've done when using Sapien is to write all my functional code in PowerShell modules and have the GUI call the modules cmdlets. I like the idea of keeping the display different from the functionality - like MVC in web dev. It's very useful if you want to reuse the function from a script.