隐藏的错误使用Get-广告组当 [英] Hiding Errors When Using Get-ADGroup

查看:98
本文介绍了隐藏的错误使用Get-广告组当的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个脚本,将建立一个新的小组,如果它不存在。我使用GET-广告组,以确保该组不存在使用下面的命令:

  $组=得到,广告组$组名-ErrorAction:SilentlyContinue -WarningAction:SilentlyContinue
 

但是,当我做我得到以下错误(我删除任何域从错误的具体数据):

  GET-广告组:找不到该对象的身份:*域*:在*组名*。
在U:\脚本\的Windows \创建-FolderAccessGroup.ps1:23字符:24
+ $组=得到,广告组<<<< $组名-ErrorAction:SilentlyContinue -WarningAction:SilentlyContinue
    + CategoryInfo:ObjectNotFound:(Y:广告组)获得-广告组],ADIdentityNot
   FoundException
    + FullyQualifiedErrorId:找不到对象身份:下:''',Microsoft.ActiveDirectory.Management.Commands.GetADGroup
 

我认为设置ErrorAction和WarningAction为SilentlyContinue会保持这个错误被显示,但它没有。

解决方案

 尝试{得到,广告组<组名>}
  抓住  {
      <做出新的组>
     }
 

I'm working on a script that will build a new group if it doesn't exist. I'm using Get-ADGroup to make sure the group doesn't exist using the following command:

$group = get-adgroup $groupName -ErrorAction:SilentlyContinue -WarningAction:SilentlyContinue 

But when I do I get the following error (I removed any domain specific data from the error):

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

I assumed setting ErrorAction and WarningAction to SilentlyContinue would keep this error from being displayed but it hasn't.

解决方案

 try {get-adgroup <groupname>}
  catch  {
      <make new group>
     }

这篇关于隐藏的错误使用Get-广告组当的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆