我正在尝试从远程服务器获取文件的最后写入时间。
这不起作用:
$server = "MyServerName"
$lastWrite = Invoke-Command -Computername $server -ScriptBlock {Get-ChildItem "\\$args[0]\hot.war" } -argumentlist $server | select -Property LastWriteTime
这确实有效:
$lastWrite = Invoke-Command -Computername $server -ScriptBlock {Get-ChildItem "\\MyServerName\hot.war" } -argumentlist $server | select -Property LastWriteTime
任何人都可以帮助使第一套作品生效吗?
最佳答案
换句话说,如果您使用的是PowerShell 3,则可以执行以下操作:
$lastWrite = Invoke-Command -Computername $server -ScriptBlock {
Get-ChildItem "\\$using:server\hot.war"
} | select -Property LastWriteTime
关于powershell - Powershell在ScriptBlock中传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30537230/