作为我正在处理的项目的一部分,我需要将一些文件从一个用户的桌面复制到登录到计算机的每个新用户。我通过桌面环境管理器运行以下命令。
%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -command "get-childitem -path $env:systemdrive\Users\Administrator\Desktop\* | Where-Object {$_.Name -like "*NAME*"} | Copy-Item -Destination $env:userprofile\Desktop"
在PowerShell中自行运行该命令可以正常工作,但是当我从外部传递它时会出错。
At line:1 char:100
+ ... {$_.Name -like *NAME*} | Copy-Item -Destination
$env:userprofile\Desktop\}
+ ~
You must provide a value expression following the '-like' operator.
At line:1 char:102
+ ... $_.Name -like *NAME*} | Copy-Item -Destination
$env:userprofile\Desktop\}
+ ~
You must provide a value expression following the '*' operator.
At line:1 char:102
+ ... $_.Name -like *NAME*} | Copy-Item -Destination
$env:userprofile\Desktop\}
+ ~~~~~~~~~~
Unexpected token 'NAME*' in expression or statement.
+ CategoryInfo : ParserError: (:) [],
ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ExpectedValueExpression
我不确定我需要在格式中调整以解决此问题,甚至可能还有更好的方法来解决此问题。任何意见都将不胜感激。
答案 0 :(得分:1)
Per Mathias建议在“解决错误之前”添加\。