我正在研究 PowerShell 管理单元,我计划将它作为 WSMan 模块的插件托管在 IIS 上。我想知道如何将附加参数从 web.config 传递到管理单元?
这里详细介绍:
托管 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>
这里 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);
}
}
}