如何比较两个foreach循环
我当前的脚本检查某些客户端上是否存在特定文件夹。 我想在检查文件夹是否存在之前检查客户端是在线还是离线。 我当前的脚本看起来像这样:
$CDS = Get-content C:\Users\XY\Desktop\Clientliste.txt
Foreach($c in $CDS) {
IF (Test-Connection -BufferSize 32 -Count 1 -ComputerName $c -Quiet) {
Foreach ($c in $CDS) {
$Test = Test-Path -path "\\$c\c$\apps\perl"
Start-Sleep -s 0.25
If ($Test -eq $True) {
Write-Host "Path exists on $c."
}
Else {
Write-Host "Path NOT exist on $c."
}
}
}
Else {
Write-Host "The remote computer " $c " is Offline"
}
}
我不知道如何链接foreach
循环,以便它们一起工作。 因为当我现在运行脚本时,它会在第二个请求第二请求之后,然后在第二 foreach 循环中,并且在完成第二个foreach时会首先离开
循环。 我不要那个。我希望,如果客户在线,它会检查路径是否存在,然后转到下一个客户端,然后再次检查它是否在线,然后...
也许您可以帮助我:)
My current script checks if a specific folder on some clients exists.
I'd like to check if the client is online or offline before checking if the folder exists.
My current script looks like this:
$CDS = Get-content C:\Users\XY\Desktop\Clientliste.txt
Foreach($c in $CDS) {
IF (Test-Connection -BufferSize 32 -Count 1 -ComputerName $c -Quiet) {
Foreach ($c in $CDS) {
$Test = Test-Path -path "\\$c\c$\apps\perl"
Start-Sleep -s 0.25
If ($Test -eq $True) {
Write-Host "Path exists on $c."
}
Else {
Write-Host "Path NOT exist on $c."
}
}
}
Else {
Write-Host "The remote computer " $c " is Offline"
}
}
I don't know how to link the foreach
loops so that they work together.
Because when I run my script now, it goes after the first if
request in the 2nd foreach
loop and it does leave it first, when it finishes the 2nd foreach
loop.
I don't want that. I want that if the client is online, it checks if the paths exists and then goes to the next client and checks again if it is online and then...
Maybe you can help me :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么从文本文件中的项目上进行了另一个相同的循环,您已经测试了机器已可以触及的?
只需删除第二个循环,然后做:
Why do another identical loop over the items from the text file is you have already tested the machine is reachable?
Just remove that second loop and do: