[英]How to pass arguments to WinRM plugin (PowerShell) hosted in IIS
I'm working on PowerShell snap-in, I plan to host it on IIS as plugin of WSMan module. 我正在使用PowerShell管理单元,我打算将其作为WSMan模块的插件托管在IIS上。 I'm wondering how to pass additional parameters from web.config to snap-in?
我想知道如何将其他参数从web.config传递到管理单元?
Here details: 这里详细说明:
Web.config file of application which host PS snap-in: 托管PS管理单元的应用程序的Web.config文件:
<system.webServer>
<system.management.wsmanagement.config>
<PluginModules>
<OperationsPlugins>
<Plugin Name="MyPSPlugin" Filename="%windir%\system32\pwrshplugin.dll" SDKVersion="1" XmlRenderingType="text">
<InitializationParameters>
<!-- I'd like to declare additional parameter for PS span-in here something like this: -->
<Param Name="myData" Value="Test" />
<Param Name="PSVersion" Value="2.0" />
<Param Name="assemblyname" Value="C:\MyServices\PowerShell\Bin\MyPSSnapin.dll" />
<Param Name="pssessionconfigurationtypename" Value="MyCompany.PowerShell.MyPSSessionConfiguration" />
</InitializationParameters>
<Resources>
<Resource ResourceUri="http://schemas.microsoft.com/powershell/Hosting.PowerShell" SupportsOptions="true">
<Capability Type="Shell" />
</Resource>
</Resources>
</Plugin>
</OperationsPlugins>
</PluginModules>
</system.management.wsmanagement.config>
</system.webServer>
Here implementation of PSSessionConfiguration: 这里实现PSSessionConfiguration:
namespace MyCompany.PowerShell
{
public class MyPSSessionConfiguration : PSSessionConfiguration
{
public override InitialSessionState GetInitialSessionState(PSSenderInfo senderInfo)
{
// read additional parameter something like this:
var myData = sendrerInfo.ApplicationArguments["myData"];
return base.GetInitialSessionState(senderInfo);
}
}
}
I'm not familiar with powershell plugin development but in web development I add a reference to System.Configuration and then use the ConfigurationManager to read in the settings from the appsettings section of the web.config into a static class with readonly properties. 我不熟悉Powershell插件开发,但是在Web开发中,我添加了对System.Configuration的引用,然后使用ConfigurationManager将web.config的appsettings部分中的设置读入具有只读属性的静态类中。 This prevents repeated reading from the web.config by caching the values.
这样可以通过缓存值来防止从web.config重复读取。 Can you apply this same technique?
可以应用同样的技术吗?
web.config web.config
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="MyData" value="Test"/>
</appSettings>
</configuration>
static class 静态类
using System;
using System.Configuration;
namespace WebTest
{
public static class CachedSettings
{
public static string MyData;
public static CachedSettings()
{
MyData = ConfigurationManager.AppSettings["MyData"];
}
}
}
I can then easily call it with 然后,我可以轻松地调用它
string a = CachedSettings.MyData;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.