Try/Catch

6 views
Skip to first unread message

Wright, John M

unread,
Apr 9, 2026, 10:12:58 AMApr 9
to ntpowe...@googlegroups.com

I have a bit of code like this.  It works to look up user accounts across three domains in the same forest.  Everything succeeds except a lookup of an account in the root domain in the second Catch.

 

Can anyone tell why this fails?

 

try {

    Get-ADUser $DH -Server Domain1.Root.Com | select name

} catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] {

    Get-ADUser $DH -Server Domain2.Root.Com | select name

} catch {

    Get-ADUser $DH -Server Root.com | select name

}

 

--

John Wright

IT Support Specialist

1800 Old Bluegrass Avenue, Louisville, KY 40215

502.708.9953

Please submit IT requests to Hazelwoo...@bluegrass.org

24 Hour Helpline 1.800.928.8000

  

CONFIDENTIALITY NOTICE: This message contains confidential information and is intended only for the individual(s) addressed in the message. If you are not the named addressee, you should not disseminate, distribute, or copy this e-mail. If you are not the intended recipient, you are notified that disclosing, distributing, or copying this e-mail is strictly prohibited.

 

Michael B. Smith

unread,
Apr 9, 2026, 10:38:21 AMApr 9
to ntpowe...@googlegroups.com

I suspect what you have written there isn’t quite what you mean. I think you mean something like this (reformatted for my readability 😊):

 

try

{

               Get-ADUser $DH -Server Domain1.Root.Com -EA Stop | select name

}

catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException]

{

               try

               {

                              Get-ADUser $DH -Server Domain2.Root.Com -EA Stop | select name

               }

catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException]

{

                              Get-ADUser $DH -Server Root.com -EA 0 | select name

--
You received this message because you are subscribed to the Google Groups "ntpowershell" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ntpowershell...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/ntpowershell/SN7PR12MB67140B7B35D1471135BCF8C291582%40SN7PR12MB6714.namprd12.prod.outlook.com.

Wright, John M

unread,
Apr 9, 2026, 8:46:56 PMApr 9
to ntpowe...@googlegroups.com

That did it.  Thanks very much.  I don’t often use Try-Catch and clearly need to brush up.

 

--

John Wright

IT Support Specialist

1800 Old Bluegrass Avenue, Louisville, KY 40215

502.708.9953

Please submit IT requests to Hazelwoo...@bluegrass.org

24 Hour Helpline 1.800.928.8000

  

CONFIDENTIALITY NOTICE: This message contains confidential information and is intended only for the individual(s) addressed in the message. If you are not the named addressee, you should not disseminate, distribute, or copy this e-mail. If you are not the intended recipient, you are notified that disclosing, distributing, or copying this e-mail is strictly prohibited.

 

From: ntpowe...@googlegroups.com <ntpowe...@googlegroups.com> On Behalf Of Michael B. Smith


Sent: Thursday, April 9, 2026 10:38 AM
To: ntpowe...@googlegroups.com

Subject: [ntpowershell] RE: Try/Catch

 

EXTERNAL EMAIL - This email was sent by a person from outside your organization. Exercise caution when clicking links, opening attachments or taking further action, before validating its authenticity.

Reply all
Reply to author
Forward
0 new messages