问题描述
对于我的O365 SharePoint Online网站,我有一些非常有用的管理PowerShell脚本,这些脚本是从计算机上的Windows PowerShell ISE运行的.我现在有一个场景,我想允许一大群人通过以下方式运行一些CSOM脚本: 单击站点上页面上的按钮或链接,因为在其计算机上安装ISE根本不可行.这甚至可行吗?我的脚本不是很复杂,但是仍然超出了SharePoint Designer工作流的范围.
For my O365 SharePoint Online sites, I have a some very useful administration PowerShell scripts that I run from the Windows PowerShell ISE on my computer. I now have a scenario where I want to allow a large group of people to run some CSOM script by clicking a button or link on a page in the site, because installing the ISE on their machine is simply not practical. Is this even doable ? My script is not very complex, but nevertheless goes beyond what is possible with a SharePoint designer workflow.
我猜想这应该是通过包含必需的javascript代码的脚本Web部件实现的,但是我需要一点帮助才能开始使用.
I'm guessing this should be possible with a script web part containing the necessary javascript code, but I need a little help to get started.
感谢任何指针,
Stephane
推荐答案
据我了解,客户端PowerShell代码无法直接调用PowerShell脚本函数,因为PowerShell脚本运行在Sever端.
As I understand, Client JavaScript code can't call PowerShell script function directly, as PowerShell script run hosed with Sever side.
一种解决方法是使用C#代码创建自定义Web服务,该程序将以编程方式执行PowerShell,并使用JavaScript代码从客户端调用Web服务的执行PowerShell函数以实现该功能.
A workaround is that create a custom web service with C# code which will execute PowerShell programmatically and from client side using JavaScript code call the web service execute PowerShell function to achieve it.
以下是一些详细的演示供您参考:
Here are some detailed demos for your reference:
从C#代码执行PowerShell脚本:
Execute PowerShell script from C# code:
http://sharepointpals.com/post/How-to-execute-PowerShell-script-(ps1-file)-from-C-code
创建自定义Web服务:
Create a custom web service:
https://msdn.microsoft.com /en-us/library/ms464040(v=office.14).aspx
JavaScript code call web service:
http://www.c -sharpcorner.com/UploadFile/0c1bb2/calling-web-service-in-html-page2/
谢谢
最好的问候
这篇关于使用按钮或链接从网页运行CSOM脚本代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!