使用C#32位和Powershell安装Windows服务器角色/功能
我试图通过执行powershell命令,使用c#安装Windows服务器角色。这是我的密码:使用C#32位和Powershell安装Windows服务器角色/功能,c#,powershell,C#,Powershell,我试图通过执行powershell命令,使用c#安装Windows服务器角色。这是我的密码: InitialSessionState iss = InitialSessionState.CreateDefault(); iss.ImportPSModule(new string[] { "ServerManager" }); Runspace PowerShellRunspace = RunspaceFactory.CreateRunspace(iss); PowerShellRunspace.
InitialSessionState iss = InitialSessionState.CreateDefault();
iss.ImportPSModule(new string[] { "ServerManager" });
Runspace PowerShellRunspace = RunspaceFactory.CreateRunspace(iss);
PowerShellRunspace.Open();
using (PowerShell powershell = PowerShell.Create())
{
powershell.Runspace = PowerShellRunspace;
powershell.AddCommand("Install-WindowsFeature");
powershell.AddArgument("XPS-Viewer");
powershell.Invoke();
}
PowerShellRunspace.Close();
但我得到一个错误,tearm“install windowsfeature”未被识别为cmdlet的名称,函数
请告诉我如何安装XPS查看器。我正在使用.NET 2.0 32位并在Windows Server 2016操作系统上执行它。您有什么Powershell版本?另外,为什么不在服务器2016操作系统上默认安装.NET 4.5?Powershell 5。此代码需要在服务器2008 R2上执行,而.NET 4.5将不存在。在服务器2008 R2上,请使用
Add WindowsFeature
或使用dism.exe
,该命令适用于所有位置。在Windows Server 2008 R2上,cmdlet的名称为old。尝试在代码中使用此选项。安装WindowsFeature
在2012年R*和2016年运行良好,但在2008年R2中使用添加WindowsFeature