Powershell 多台电脑输出的测试路径不是我想要的
测试“我的楼层机器”的路径以确保目标为真,然后在移动文件后测试文件是否存在。我怎样才能让这个结果出来,让下半场是真是假 如果我分别运行它们,就会得到一个输出Powershell 多台电脑输出的测试路径不是我想要的,powershell,Powershell,测试“我的楼层机器”的路径以确保目标为真,然后在移动文件后测试文件是否存在。我怎样才能让这个结果出来,让下半场是真是假 如果我分别运行它们,就会得到一个输出 PS C:\Users\amandaw.QPC> Get-Content C:\apps\currentcomputers.txt | ` Select-Object @{Name='ComputerName';Expression={$_}},@{Name='ItemExist';Expression={ Test-Path
PS C:\Users\amandaw.QPC> Get-Content C:\apps\currentcomputers.txt | `
Select-Object @{Name='ComputerName';Expression={$_}},@{Name='ItemExist';Expression={ Test-Path "\\$_\c$\apps\$file"}}
ComputerName ItemExist
------------ ---------
Commercial1 True
TC-15 True
Floor03 True
Floor04 True
Mixit-PC True
TC2018B True
FLOOR07 True
tc2017p True
Floor09 True
TC2017k True
tc2017g True
ptc-6 True
tc2017a True
tc2017b True
Floor15 True
tc2019z True
tc2019b True
(复制文件-由于不需要帮助而忽略) 输出
PS C:\Users\amandaw.QPC> C:\Workstation\Documents\WindowsPowerShell.batch\Untitled5.ps1
ComputerName PathExist
------------ ---------
Commercial1 True
TC-15 True
Floor03 True
Floor04 True
Mixit-PC True
TC2018B True
FLOOR07 True
tc2017p True
Floor09 True
TC2017k True
tc2017g True
ptc-6 True
tc2017a True
tc2017b True
Floor15 True
tc2019z True
tc2019b True
Commercial1
TC-15
Floor03
Floor04
Mixit-PC
TC2018B
FLOOR07
tc2017p
Floor09
TC2017k
tc2017g
ptc-6
tc2017a
tc2017b
Floor15
tc2019z
tc2019b
- 我在计算机中读取csv文件
(提供收割台)和 - 用
附加两个新(空)字段选择对象
- 通过使用
和测试路径
-PathType
> $Computers
Name PathExists ItemExists
---- ---------- ----------
Commercial1 True True
TC-15 True False
Floor03 False False
太棒了!谢谢我特别喜欢户外的景色。我是powershell的新手,以前从未使用过它。我需要做的唯一修改是第15行-路径类型(Leaf)而不是-路径类型Leaf}很抱歉输入错误,感谢您的反馈。暗示一个新的贡献者:如果答案解决了你的问题,或者你发现它有帮助,你应该考虑吗?和/或(一旦你得到15分,就会看到)
PS C:\Users\amandaw.QPC> C:\Workstation\Documents\WindowsPowerShell.batch\Untitled5.ps1
ComputerName PathExist
------------ ---------
Commercial1 True
TC-15 True
Floor03 True
Floor04 True
Mixit-PC True
TC2018B True
FLOOR07 True
tc2017p True
Floor09 True
TC2017k True
tc2017g True
ptc-6 True
tc2017a True
tc2017b True
Floor15 True
tc2019z True
tc2019b True
Commercial1
TC-15
Floor03
Floor04
Mixit-PC
TC2018B
FLOOR07
tc2017p
Floor09
TC2017k
tc2017g
ptc-6
tc2017a
tc2017b
Floor15
tc2019z
tc2019b
## Q:\Test\2019\06\26\SO_56779528.ps1
# path to Item to be copied
$item = Get-Item "C:\Workstation\Pictures\pngtree___material_distribution_939546_1MJ_icon.ico"
#item
$file = $item.Name
$Computers = Import-Csv C:\apps\currentcomputers.txt -Header Name |
Select-Object *,PathExist,ItemExist
ForEach($Computer in $Computers){
$Computer.PathExist = (Test-Path "\\$($Computer.Name)\c`$\apps" -PathType Container)
#(copy the files- left out since don't need help with that)
$Computer.ItemExist = (Test-Path "\\$($Computer.Name)\c`$\apps\$file" -PathType Leaf)
}
$Computers
# $Computers | Out-GridView
# $Computers | Export-Csv C:\apps\Computers.csv -NoTypeInformation
> $Computers
Name PathExists ItemExists
---- ---------- ----------
Commercial1 True True
TC-15 True False
Floor03 False False