powershell - Invoke-Command 后的 Get-ChildItem 在 Windows 7 上不起作用
问题描述
我在 PowerShell 上有一个脚本,可以在少数 Windows 7 和 Windows 10 计算机上远程调用命令。
远程运行的命令基本上会在 C:\ 分区内的目录上创建几个文件,并在完成调用我正在使用的命令Get-ChildItem
来Where-Object
选择特定文件之后。
例子:
$ComputerArray = @("win10-01", "Win10-02", "win7-01", "WIn7-02")
foreach ($comp in $ComputerArray) {
Invoke-Command -ComputerName $comp -ScriptBlock {
cd c:\temp
New-Item test.txt
}
$file = Get-ChildItem \\$comp\C$\temp |
Where-Object {$_.Name -match "test"}
if ($file -eq $null) {
'there is no file such as test'
} else {
$file
}
}
在 Windows 10 机器上,有一个结果,它告诉我有一个“test.txt”文件,在 Windows 7 上它显示“没有诸如 test 之类的文件”。
不用说,我所有的机器都在运行 PowerShell 5.1。
解决方案
推荐阅读
- vue.js - Vue jsx,渲染函数中的h已定义但从未使用过
- java - 为什么我的简单数组只在 java 中打印零?
- php - MySQL cronjob 脚本到 MySQLi cronjob 脚本
- bash - 使用 sed 命令搜索一个单词并替换下一个单词
- python-3.x - 如何运行处理 s3 存储桶内容的脚本?
- postgresql - 从另一个查询调用时,返回 SETOF 记录丢失记录类型
- javascript - 使用 mkdirsync 时节点中的异常
- jenkins - 将 Terraform Plan 输出集成到 Jenkins
- android - 如何在 Flutter 中连接 onPressed 和 onTap?
- java - 如何获取 JWK 并在 JWT 签名中使用它们?