Capture and redirect warning messages

Hello,

I have a script that is executing a ConfigMgr cmdlet:

New-CMDeviceCollection -Name $CNAME -LimitingCollectionName "All Systems" -RefreshType Both

When executed, if a collection already exists with the provided name it outputs the following warning message:

WARNING: The collection cannot be created because a collection with the specified name already exists. Create a collection with a different name.

I would like to capture this message and redirect its output to the screen in the following format:

WARNING: $CNAME cannot be created because a collection with the specified name already exists.

I have read about using 3>&1 but I'm having trouble finding a similar example to follow. Any help is greatly appreciated!

September 9th, 2015 3:07pm

Thanks Mike. That did the trick!
Free Windows Admin Tool Kit Click here and download it now
September 11th, 2015 12:59pm

Cheers, you're very welcome.
September 11th, 2015 1:11pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics