测试路径无法检查文件夹路径
Test path fails to check for folder path
我正在尝试检查远程中是否存在特定文件夹 servers.I 有文件 PathList.txt,其中包含服务器地址和指向 check.But 的文件夹路径 即使在我的本地计算机(我给了我的本地机器 IP)。当路径实际存在时,它说路径不存在
$ServerPaths = Get-Content .\PathList.txt
#Check for paths in servers.
Foreach ($s in $ServerPaths)
{
$Server,$Paths = $s.split('=',2)
$AllPaths = $Paths -split ','
$Server=$Server.Trim()
Foreach ($Path in $AllPaths)
{
$Path=$Path.Trim()
$CheckPath = "\"+$Server+"\"+$Path
if(Test-Path $CheckPath)
{
Write-host $Server $Path "Path exists"
}
else
{
Write-host $Server $Path "Path does not exists"
}
}
}
PathList.txt 包含
10.247.211.12 = D$\Install, D$\Dir
我已经检查了你的代码,它工作正常,但前提是你之前访问过该路径(因此它可以缓存凭据),或者你当前的用户可以访问共享。我建议您将 -Credential
参数添加到 Test-Path
调用中。
我正在尝试检查远程中是否存在特定文件夹 servers.I 有文件 PathList.txt,其中包含服务器地址和指向 check.But 的文件夹路径 即使在我的本地计算机(我给了我的本地机器 IP)。当路径实际存在时,它说路径不存在
$ServerPaths = Get-Content .\PathList.txt
#Check for paths in servers.
Foreach ($s in $ServerPaths)
{
$Server,$Paths = $s.split('=',2)
$AllPaths = $Paths -split ','
$Server=$Server.Trim()
Foreach ($Path in $AllPaths)
{
$Path=$Path.Trim()
$CheckPath = "\"+$Server+"\"+$Path
if(Test-Path $CheckPath)
{
Write-host $Server $Path "Path exists"
}
else
{
Write-host $Server $Path "Path does not exists"
}
}
}
PathList.txt 包含
10.247.211.12 = D$\Install, D$\Dir
我已经检查了你的代码,它工作正常,但前提是你之前访问过该路径(因此它可以缓存凭据),或者你当前的用户可以访问共享。我建议您将 -Credential
参数添加到 Test-Path
调用中。