Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing a powershell script and I want to find out the result of a New-QADUser command if the command fails.

I found an argument to the New-QADUser command called -WhatIf (which I believe to be run if the cmdlet call fails) but I can't find any good examples of using it, and my attempts to use it have failed.

share|improve this question

if a cmdlet fails it returns an error. You can trap errors in powershell. See finding and avoiding errors

the -whatif parameter tells the cmdlet not to actually perform any actions but report of what the cmdlet would have done if allowed to.

share|improve this answer
that's a really good reference! Thanks! – leeand00 Mar 31 '11 at 17:32
It is possible to trap an Exception of a particular type. But what type should I trap if I only want it to ignore Exceptions that occur when a user already exists? – leeand00 Mar 31 '11 at 18:06

The -whatif parameter is pretty standard in PowerShell. It will tell you (as best it can) what will happen if you execute the command that the -whatif parameter is appended to. It must be run BEFORE you run the command or it's not useful.

Here's an example:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.