检查 PowerShell 对象是否存在的最佳方法? [英] Best way to check if an PowerShell Object exist?
本文介绍了检查 PowerShell 对象是否存在的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找检查 Com 对象是否存在的最佳方法.
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?
推荐答案
我会坚持使用 $null
检查,因为除了 ''
之外的任何值(空字符串), 0
, $false
和 $null
将通过检查: if ($ie) {...}
.
I would stick with the $null
check since any value other than ''
(empty string), 0
, $false
and $null
will pass the check: if ($ie) {...}
.
这篇关于检查 PowerShell 对象是否存在的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文