首页 > 解决方案 > Get-Childitem 找不到驱动器。名为“X”的驱动器不存在

问题描述

我正在编写一个脚本来使用文件资源管理器中的映射驱动器使用 powershell 复制文件。它有上述错误信息。这是它的样子:

function CopyFileToFolderUNC($SourcePath, $DestinationPath){
   $temp1 = Get-ChildItem -Path $SourcePath -Recurse -Force #this is the line of error message
   Copy-Item -Path $SourcePath -Destination $DestinationPath #source:\* -Destination target  #watch out for login boxes when test this
}

#start here
$tempSource = "X:\Credentialing\FORMS"
$ToLocation = "C:\Users\me\Documents\2018\powershellFiles\toLoc" 

CopyFileToFolderUNC $tempSource $ToLocation

它在 Copy-Item 行上具有相同的错误消息(如果我注释掉 Get-ChildItem 行),但在此之前它在 Get-ChildItem 中失败。 如何让它使用运行脚本的计算机上的映射驱动器?我在笔记本电脑上运行这个。

我在命令行的 powershell 中设置了执行策略 RemoteSigned。

当我在命令行的 powershell 中运行 Get-PSSessionConfiguration 时,我拥有此权限:

权限:NT AUTHORITY\INTERACTIVE AccessAllowed、BUILTIN\Administrators AccessAllowed、BUILTIN\Remote Management Users AccessAllowed

我以管理员身份运行。Powershell 提示符是:

[DBG]:PS C:\WINDOWS\system32>>

$PSVersionTable.PSVersion:

Major  Minor  Build  Revision
-----  -----  -----  -------- 
5      1      16299  666

我查看了powershell 映射驱动器 E,但他们在服务器上使用映射驱动器,所以我不确定他们在示例中需要做什么。

标签: powershellmapped-drive

解决方案


我发现了这个:网络使用

所以我加了

if(-Not (Test-Path "X:\")) {net use X: \\NDRIVE01\Svcs_FG}

现在它至少找到了映射的驱动器。


推荐阅读