Powershell,验证当前目录是否等于的最佳方法

Powershell,验证当前目录是否等于的最佳方法,powershell,powershell-2.0,powershell-3.0,Powershell,Powershell 2.0,Powershell 3.0,我对powershell是新手 我有以下问题:我试图检查当前目录是否等于存储在变量上的预期目录 比如: Set-Variable tsDir -Value "mydir\subdir" if(!((Test-Path [$tsDir]) -and (($pwd).path -eq $tsDir))) { Write-Host "Wrong dir" exit } Keep-Going ... 然而,即使打印$pwd和$tsDir看起

我对powershell是新手

我有以下问题:我试图检查当前目录是否等于存储在变量上的预期目录

比如:

Set-Variable tsDir  -Value "mydir\subdir"
if(!((Test-Path [$tsDir]) -and (($pwd).path -eq $tsDir)))
{
     Write-Host "Wrong dir"
     exit
}
Keep-Going ...
然而,即使打印$pwd和$tsDir看起来相等,它也不起作用。我需要特别的东西吗?也许是返回一个对象,我需要将其转换为字符串?我怎么做

我还想使它不区分大小写(windows)


感谢您给我的任何提示:)

$pwd包含完整路径。您似乎正在搜索部分路径。您可以尝试
$pwd.path.Contains($tsDir)
。谢谢,您让我走上了正确的道路。我最后做了:if(!((测试路径$tsDir)-和($pwd.Path.ToLower().Equals($tsDir.ToLower()))