【发布时间】:2021-12-17 11:24:17
【问题描述】:
如何在我的 C# 程序中为 cmdlet New-LocalGroup 捕获 Powershell 异常 AccessDeniedException 和 GroupExistsException
try
{
PowerShell ps = PowerShell.Create();
ps.AddCommand("New-LocalGroup");
ps.AddParameter("Name", groupName);
ps.AddParameter("Description", description);
ps.Invoke();
}
catch (Exception ex)
{
if (ex is ?)
throw ex;
}
到目前为止,我有来自 Microsoft 文档 here 的此链接。
【问题讨论】:
标签: c# powershell exception .net-4.0