从SharePoint启动PowerShell [英] Launch PowerShell from SharePoint
问题描述
我有一个PowerShell脚本,我需要每月为另一个部门从SharePoint服务器运行该脚本,而我想将此任务委托给他们,以便他们可以从自己的计算机(而不是服务器)运行它).我做了以下JavaScript 在Webpart中:
I have a PowerShell script that I need to run from the SharePoint server on a monthly basis for another department, and I wanted to delegate this task to them instead so they can run it from their computers (not server). I did the following JavaScript inside a webpart:
<SCRIPT>
function LaunchPowerShell()
{
window.alert("Running Monthly Process!");
AppPath = '"\\\\SERVER\\C$\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" -ExecutionPolicy ByPass -File \\\\SERVER\\Dept\\MonthlyProcess.ps1';
WSH = new ActiveXObject("WScript.Shell");
WSH.run(AppPath);
}
</SCRIPT>
<button style="background-color:lightblue" onclick="LaunchPowerShell()">Run Monthly Process</button>
当我对此进行测试时,当我登录SharePoint Server并按一下SharePoint网站上的按钮时,它就可以正常工作.但是,如果我从笔记本电脑尝试相同的操作,则会得到"window.alert"弹出(如预期),但是 每月流程不运行.
When I test this out, it works just fine when I'm logged in the SharePoint Server and press on the button from the SharePoint site. However, If I try the same thing from my laptop, I get the "window.alert" pop-up (as expected), but the monthly process doesn't run.
有什么建议吗?
推荐答案
哦,显然我需要将以下行添加到我的PS脚本"MonthlyProcess.ps1"中:
Oh, apparently I needed to add the following line to my PS script "MonthlyProcess.ps1":
Add-PSSnapin Microsoft.SharePoint.Powershell
PS脚本现在可以运行,但是它确实会启动PS窗口,然后关闭.因此,我将对其进行隐藏,以免混淆用户:)
The PS script works now, but it does launch the PS window and then closes. So, I'll work on hiding that so it doesn't confuse the users :)
这篇关于从SharePoint启动PowerShell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!