Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Capturing Output from Module Import

$
0
0

Hi Guys,

I'm importing the AD module which is fine, but I need to control what happen's when the environment impacts. Anyway, I'm trying to avoid rambling so here goes. The first test is what happens when the module is imported but cannot see a DC:

WARNING: Error initializing default drive: 'Unable to find a default server with Active Directory Web Services running.'.

Now, I want to trap this string in a variable and then analyze it using -like. The problem is, Try Catch won't catch it. Or maybe it's my Try Catch that won't catch it!

This behaviour can be reproduced simply by disabling your NIC and trying to import the AD module. Can anyone show me an example of how to catch this warning message?

Best Regards,

James


Viewing all articles
Browse latest Browse all 6937

Trending Articles