请教育我。 我试图testing一组文件是否存在于一组计算机的桌面上。 有些电脑是Windows 7,有些则是Windows XP。 当我运行代码时,它不会在每台计算机上testingpath,并将每台计算机都以“有URL”的forms返回,即使是我知道该文件不存在的计算机。 我不确定我哪里出了问题。
$a = Get-Content "C:\Computers.txt" $windowsXP = "\\$i\c$\Documents and Settings\All Users\Desktop\file.url" $windows7 = "\\$i\c$\Users\Public\Desktop\file.url" ForEach ($i in $a){ #Test file on WindowsXP if ((test-path $windowsXP) -eq $True) {Write-Output "$i WindowsXP has URL"} elseif ((test-path $windowsXP) -eq $False) {Write-Output "$i WindowsXP needs URL"} #Test file on Windows7 elseif((test-path $windows7) -eq $True) {Write-Output "$I Windows7 has URL"} elseif ((test-path $windows7) -eq $False) {Write-Output "$I Windows7 needs URL"} }
试试这个(未经testing)。 虽然它仍然没有得到绕过testing盲人的事实。
$a = Get-Content "C:\Computers.txt" ForEach ($i in $a){ $windowsXP = "\\$i\c$\Documents and Settings\All Users\Desktop\file.url" $windows7 = "\\$i\c$\Users\Public\Desktop\file.url" #Test file on WindowsXP Write-Output("$i - Checking WindowsXP Location") if ((test-path $windowsXP) -eq $True) {Write-Output "File Found"} elseif ((test-path $windowsXP) -eq $False) {Write-Output "File Not Found "} #Test file on Windows7 Write-Output("$i - Checking Windows7 Location") if((test-path $windows7) -eq $True) {Write-Output "File FoundL"} elseif ((test-path $windows7) -eq $False) {Write-Output "File Not Found"} }