Thursday, 8 August 2013

How Can I Silence this PowerShell Error?

How Can I Silence this PowerShell Error?

I have an If statement in my script checking if an AD Object already
exists. However, none of these evaluations prevent the host from printing
the undesired evaluation "Directory object not found."
!$(Get-ADObject -Identity $ImportedObject.DistinguishedName -ErrorAction
SilentlyContinue)
[void](!$(Get-ADObject -Identity $ImportedObject.DistinguishedName))
!$($(Get-ADObject -Identity $ImportedObject.DistinguishedName) | Out-Null)
$ErrorAction = $CurrentErrorAction
$ErrorAction = "SilentlyContinue"
!$(Get-ADObject -Identity $ImportedObject.DistinguishedName)
$ErrorAction = $CurrentErrorAction

No comments:

Post a Comment