Alex Rivera | Logout

Best way to check if an PowerShell Object exist?

Asked 2010-12-13T14:56:27.303
105

I am looking for the best way to check if a Com Object exists.

Here is the code that I have; I'd like to improve the last line:

$ie = New-Object -ComObject InternetExplorer.Application
$ie.Navigate("http://www.stackoverflow.com")
$ie.Visible = $true

$ie -ne $null #Are there better options?
Edit
Report

1 Answer

124

I would stick with the $null check since any value other than '' (empty string), 0, $false and $null will pass the check: if ($ie) {...}.

answered 2010-12-13T16:39:25.213

Your Answer