Test-Pathコマンドレットを使う。存在すればTrue、存在しなければFalseを返す。-PathTypeオプションにLeaf(ファイル)かContainer(ディレクトリー)を指定することで、ファイルかディレクトリーの指定をすることができる。特に指定をしなければ、ファイルかディレクトリーが存在すればTrueを返す。
> Test-Path C:\Windows\explorer.exe
True
> Test-Path C:\Windows
True
> Test-Path C:\Windows\explorer.exe -PathType Leaf
True
> Test-Path C:\Windows\explorer.exe -PathType Container
False
> Test-Path C:\Windows -PathType Leaf
False
> Test-Path C:\Windows -PathType Container
True
> Test-Path C:\Windows\*.exe -PathType Leaf
True
> Test-Path C:\Windows\*.exeexe -PathType Leaf
False