判断路径\文件是否存在

$Folder = 'C:\Windows'

if (Test-Path -Path $Folder) { "Path exists!" } else { "Path doesn't exist." }

$File = 'C:\Windows\a.txt' if (Test-Path -Path $File) { "File exists!" } else { "File doesn't exist." }

判断命令是否存在 $cmdName = nslookup if (Get-Command $cmdName -errorAction SilentlyContinue) { "$cmdName exists" }