1

我在使用 Move-Item 轰炸的 powershell 脚本中有以下代码:不支持给定路径的格式。我似乎无法弄清楚我做错了什么。

 $computer = gc env:computername

 write-host "Moving archives `r`n"
 gci -Path $logdir -Recurse -Include *.7z |  ForEach-Object {  
 mi -Path $_.FullName -Destination \\storage\logs\iis\$computer\$_.Directory.Name\ -force -WhatIf
 }

任何人都可以给我任何指示吗?

4

1 回答 1

4

如果要在$_cmdlet 参数参数的表达式中使用管道对象,则参数必须首先支持管道绑定,其次,您必须将参数放在脚本块中,例如:

ls *.txt | mi -Destination {"\\storage\logs\iis\$computer\$($_.Directory.Name)"} -force -WhatIf 
于 2012-10-26T22:00:06.013 回答