在使用foreach的简单powershell命令复制中需要帮助
|
我是Powershell的新手,这个问题将证明这一点。我正在尝试从命令行执行一个简单的任务,其中有一个txt文件,其中包含以分号分隔的文件名,例如...
fnameA.ext;fnameB.ext;fnameC.ext;....
我正在尝试运行一个命令,该命令将解析此文件,用分号分隔内容,然后对每个文件运行复制命令到所需目录。
这是我正在运行的命令:
gc myfile.txt |% {$_.split(\";\") | copy $_ \"C:\\my\\desired\\directory\"}
但是我在列表中的每个项目上都遇到了这样的错误...
Copy-Item : The input object cannot be bound to any parameters for the command either because the command does not take
pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
At line:1 char:36
+ gc bla.txt |% {$_.split(\";\") | copy <<<< $_ \"C:\\my\\desired\\directory\"}
+ CategoryInfo : InvalidArgument: (fileA.txt:String) [Copy-Item], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.CopyItemCommand
没有找到相关结果
已邀请:
4 个回复
丧泉缝锋
勺的驴吓识
另请注意,您使用了文件的相对路径,这可能会给您带来麻烦。
妒垮
蓄荣糖些