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.


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.

  • 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: http://www.computerperformance.co.uk/powershell/powershell_whatif_confirm.htm#PowerShell_-whatIf_Example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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