Hi,
I often use cmdlets in if statements, most of the time the case is similiar to verify that an (AD)object does not exist before proceeding with creation. So lets take this for an example:
if (!(get-qadobject -Identity $Id)) { Write-Host "The object does not exist, create" }else{ Write-Host "The object does exist, do not create" }
The problem is that i sometimes get a lot of error output printed. Like:
"Get-QADObject : Cannot resolve DN for the given identity: 'activedirectory.ad/path/to/OU'At C:\Scripts\NoSched\createGroup.ps1:18 char:20+ If (!(get-qadobject <<<< -Identity $GroupOU -erroraction SilentlyContinue)) {"
Is that the effect of -ea silentlycontinue? Thought it would suppress the error message. I have tried using -errorvariable also but it does not suppress the errors anyway.
I would love to have common parameter that is something like -returnbool and then have the cmdlet return $TRUE on success and $FALSE on failure/error.
Or maybe there is an other way in powershell to make this kind of checks. I have read about_common but it does not help me determine if i use -ea and -ev in the wrong way. How do you verify the existence/non-existence of an object before you remove/create. Maybe there is a way to let the cmdlet responsible for the creation/removal to handle that verification?
Frejen
|