C# 查找C的Microsoft.Windows.ServerManager库#
我正在使用C# 查找C的Microsoft.Windows.ServerManager库#,c#,.net,windows,powershell,C#,.net,Windows,Powershell,我正在使用System.Management.Automation命名空间,以便在C#.NET程序中使用powershell 但是,根据addwindowsfeature返回Microsoft.Windows.ServerManager.Commands.FeatureOperationResult类型 此对象未在MSDN上记录,但我可以使用PowerShell和Get Member命令检索其成员 PS C:\Users\Administrator> $RES[0] | Get-Membe
System.Management.Automation
命名空间,以便在C#.NET程序中使用powershell
但是,根据addwindowsfeature
返回Microsoft.Windows.ServerManager.Commands.FeatureOperationResult
类型
此对象未在MSDN上记录,但我可以使用PowerShell和Get Member
命令检索其成员
PS C:\Users\Administrator> $RES[0] | Get-Member
TypeName: Microsoft.Windows.ServerManager.Commands.FeatureOperationResult
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
ExitCode Property Microsoft.Windows.ServerManager.Commands.FeatureOperationExitCode ExitCode {get;}
FeatureResult Property Microsoft.Windows.ServerManager.Commands.FeatureResult[] FeatureResult {get;}
RestartNeeded Property Microsoft.Windows.ServerManager.Commands.RestartState RestartNeeded {get;}
Success Property System.Boolean Success {get;}
现在我想在C#中使用这种类型,但为此,我需要具有此命名空间的库。我只能找到
C:\Windows\winsxs\amd64_microsoft.windows.servermanager_31bf3856ad364e35_6.1.7601.17514_none_c70b231167ed6fc3
Microsoft.Windows.ServerManager.dll所在的目录。此库可以在visual studio中引用,但其命名空间不包含。命令命名空间(?)类(?)
你知道我在哪里能找到合适的图书馆吗
也许有办法在不添加此库作为引用的情况下检索Success(boolean)属性李>
在C#$RES
中,我发现它的类型是命令的结果。为了能够使用addwindowsfeature
,您必须首先导入名为ServerManager
的服务器模块。此服务器模块位于中
C:\Windows\System32\WindowsPowerShell\v1.0\Modules\ServerManager
目录。在同一目录中,有一个包含行的ServerManager.psd1
文件
NestedModules = 'Microsoft.Windows.ServerManager.PowerShell'
如果搜索Microsoft.Windows.ServerManager.PowerShell.dll
library。您应该找到它的一个实例,该实例包含我在问题中提到的.Commands
命名空间。相关DLL的名称和位置是一个实现细节,可能会随着版本的不同而变化。我发现,在PowerShell结果中处理结构化对象的最简单方法是使用C#“动态”功能。例如:
public bool FeatureIsInstalled(string name)
{
bool result = false;
using (Pipeline pipeline = runspace.CreatePipeline(
string.Format("Get-WindowsFeature '{0}'", name)))
{
Collection<PSObject> output = pipeline.Invoke();
if (output.Count > 0)
{
dynamic o1 = output[0];
result = (bool)o1.Installed;
}
}
return result;
}
public bool功能已安装(字符串名称)
{
布尔结果=假;
使用(Pipeline Pipeline=runspace.CreatePipeline)(
Format(“获取WindowsFeature“{0}”,名称)))
{
集合输出=pipeline.Invoke();
如果(output.Count>0)
{
动态o1=输出[0];
结果=(bool)o1.0已安装;
}
}
返回结果;
}