【发布时间】:2020-03-15 12:04:11
【问题描述】:
我一直在用我尝试了几种不同方法的 powershell 脚本敲我的脑袋,想知道是否有人可以提供帮助?
现在不确定我是否只是在做一些愚蠢的事情,在此先感谢
目标:
要将 vbs 文件从用户的 homedrives 复制到不同的位置,vbs 文件的位置会根据需要帐户管理员执行的用户而更改,因此这需要可变。它从一个文本文件中获取位置,该文本文件包括要到达的确切路径和已经创建的将文件复制到的目标。
我目前遇到的问题:
$location = Get-Content C:\Users\Administrator\Desktop\here\drive4.txt | Out-String
$dest = "C:\Users\Administrator\Desktop\here"
Get-ChildItem -Path $location |
Copy-Item -Destination $dest -Recurse -Container -filter "peruser.vbs"
write-host $location
Read-Host -Prompt "Press Enter to continue or CTRL+C to quit"
问题
请参阅下面的内容,我已将写入主机显示为 powershell 试图到达的位置,作为旁注,我可以通过文件资源管理器很好地到达该位置
收到错误
Get-ChildItem : Illegal characters in path.
At C:\Users\Administrator\Desktop\MapNetworkDrives2.ps1:17 char:1
+ Get-ChildItem -Path $location | Copy-Item -Destination $dest -Recurse -Container ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (\\WIN-7V7GI0R7C...
:String) [Get-ChildItem], ArgumentException
+ FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.GetChildItemCommand
Get-ChildItem : Cannot find path '\\WIN-7V7GI0R7CFK\homedrives\Onetest$
' because it does not exist.
At C:\Users\Administrator\Desktop\MapNetworkDrives2.ps1:17 char:1
+ Get-ChildItem -Path $location | Copy-Item -Destination $dest -Recurse -Container ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (\\WIN-7V7GI0R7C...
:String) [Get-ChildItem], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
【问题讨论】:
-
你的变量得到了什么?命令后的 $location 和 $dest 有什么?写入 $location = Get-Content C:\Users\Administrator\Desktop\here\drive4.txt | Out-String 然后 $location 检查它是否是你想要的路径。另一个错误最后有个$,是系统目录吗?可能是导致错误的 $ 符号。
-
您好,我的变量位置正确 -$Location 指向 \\WIN-7V7GI0R7CFK\homedrives\Onetest$,$dest 指向 C:\Users\Administrator\Desktop\here .我试图访问的目录是一个共享驱动器,我们所有用户的 homedrives 都有一个 $ 结束
-
尝试使用
-Force开关Get-ChildItem