相关疑难解决方法(0)

GetA PSSessionConfiguration的ErrorActionPreference和ErrorAction SilentlyContinue

我的情况:

$ErrorActionPreference = "Stop";
"1 - $ErrorActionPreference;"
Get-ChildItem NoSuchFile.txt -ErrorAction SilentlyContinue;
"2 - $ErrorActionPreference;"
Get-ChildItem NoSuchFile.txt -ErrorAction Stop;
"3 - $ErrorActionPreference;"
Run Code Online (Sandbox Code Playgroud)

输出:

1 - 停止;
2 - 停止;
并显示错误...

现在,

$ErrorActionPreference = "Stop";
"1 - $ErrorActionPreference;"
(Get-PSSessionConfiguration -Name "MyShellUri" -ErrorAction SilentlyContinue)
"2 - $ErrorActionPreference;"
Run Code Online (Sandbox Code Playgroud)

输出:

1 - 停止;
并显示错误...

为什么不能为Get-PSSessionConfiguration工作-ErrorAction SilentlyContinue?

更新:

现在,

$ErrorActionPreference = "Continue"
"1 - $ErrorActionPreference;"
(Get-PSSessionConfiguration -Name "MyShellUri" -ErrorAction SilentlyContinue)
"2 - $ErrorActionPreference;"
Run Code Online (Sandbox Code Playgroud)

输出:

1 - 继续;
2 - 继续;

现在,

$ErrorActionPreference = "SilentlyContinue"
"1 - …
Run Code Online (Sandbox Code Playgroud)

error-handling powershell silent

23
推荐指数
1
解决办法
13万
查看次数

使用Get-ADGroup时隐藏错误

我正在编写一个脚本,如果它不存在,将构建一个新组.我正在使用Get-ADGroup使用以下命令确保该组不存在:

$group = get-adgroup $groupName -ErrorAction:SilentlyContinue -WarningAction:SilentlyContinue 
Run Code Online (Sandbox Code Playgroud)

但是当我这样做时,我收到以下错误(我从错误中删除了任何特定于域的数据):

Get-ADGroup : Cannot find an object with identity: '*group name*' under: '*domain*'.
At U:\Scripts\Windows\Create-FolderAccessGroup.ps1:23 char:24
+ $group = get-adgroup <<<< $groupName -ErrorAction:SilentlyContinue -WarningAction:SilentlyContinue
    + CategoryInfo          : ObjectNotFound: (y:ADGroup) [Get-ADGroup], ADIdentityNot
   FoundException
    + FullyQualifiedErrorId : Cannot find an object with identity: '' under: ''.,Microsoft.ActiveDirectory.Management.Commands.GetADGroup
Run Code Online (Sandbox Code Playgroud)

我假设设置ErrorAction和WarningAction为SilentlyContinue将保持此错误显示,但它没有.

powershell active-directory

13
推荐指数
3
解决办法
4万
查看次数