gpt4 book ai didi

powershell - Powershell在ScriptBlock中传递参数

转载 作者:行者123 更新时间:2023-12-03 01:15:40 24 4
gpt4 key购买 nike

我正在尝试从远程服务器获取文件的最后写入时间。

这不起作用:

$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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com