C# スクリプトを使用して Powershell で接続ブローカーを構成する際に問題があります。
モジュールをインポートするときは、remotedesktopservices
以前にセッション ホスト ロールがインストールされて使用されていたため、コネクション ブローカー ロールをインストールした後、正しい出力を得るためにスクリプトを再起動する必要があります。
Powershell を直接使用すると、動作を再現できます。
呼び出すコマンドは次のとおりです。
PS C:\Windows\system32> import-module servermanager
PS C:\Windows\system32> import-module remotedesktopservices
PS C:\Windows\system32> add-windowsfeature rds-connection-broker
Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
True No Success {Remotedesktop-ConnectionBroker}
PS C:\Windows\system32> ls rds:
Directory: RDS:
Name Type CurrentValue GP PermissibleValues PermissibleOperations
---- ---- ------------ -- ----------------- ---------------------
RDSConfiguration Container - Get-Item, Get-ChildItem
RemoteApp Container - Get-Item, Get-ChildItem
PS C:\Windows\system32> import-module -force remotedesktopservices
PS C:\Windows\system32> ls rds:
Directory: RDS:
Name Type CurrentValue GP PermissibleValues PermissibleOperations
---- ---- ------------ -- ----------------- ---------------------
RDSConfiguration Container - Get-Item, Get-ChildItem
RemoteApp Container - Get-Item, Get-ChildItem
Powershell またはプログラムを再起動すると、結果は (正しく) 次のようになります。
PS C:\Windows\system32> ls rds:
Directory: RDS:
Name Type CurrentValue GP PermissibleValues PermissibleOperations
---- ---- ------------ -- ----------------- ---------------------
RDSConfiguration Container - Get-Item, Get-ChildItem
RDSFarms Container - Get-Item, Get-ChildItem
RemoteApp Container - Get-Item, Get-ChildItem
ConnectionBroker Container - Get-Item, Get-ChildItem
プログラムを再起動せずにこの出力が必要です。C# で新しく新しい Powershell を入手することは可能ですか? 「remove-module」と「import-module」は役に立ちませんでした。
これは、Powershell 実行空間を取得するための C# コードです。
InitialSessionState iss = InitialSessionState.CreateDefault();
iss.ThrowOnRunspaceOpenError = true;
iss.ImportPSModule(initialRoles);
RemoteHost.powerShellRunspace = RunspaceFactory.CreateRunspace(iss);
RemoteHost.powerShellRunspace.Open();
同じように新しい PowerShell 実行空間を作成しても、古い Powershell が読み込まれているようです