我正在尝试通过执行powershell命令使用c#安装Windows Server角色。这是我的代码:
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();
但我收到错误The tearm' install-windowsfeature'不被识别为cmdlet的名称,函数....
请告诉我如何安装XPS-Viewer。我使用的是32位.NET 2.0并在Windows Server 2016操作系统上执行它。