【发布时间】:2020-01-27 21:26:53
【问题描述】:
您好,我希望我的 powershell 脚本能够从映射驱动器 (Z:) 复制文件并将其复制到域“C:/temp/”文件夹中的用户。目前,我的脚本如下所示。
$Computer = Read-Host -Prompt 'Enter the Computer Name you are accessing'
########## Install Software On PC ##########
New-Item -ItemType directory -Path "\\$Computer\c$\temp\openVPN"
Copy-Item "Z:\(15) IT\VPN\openvpn-install-2.4.8-I602-Win7.exe" "\\$Computer\c$\temp\" -Recurse
Copy-Item "Z:\(15) IT\VPN\office.opvn" "\\$Computer\c$\temp\" -Recurse
Write-Host "Installing openVPN on $Computer"
Invoke-Command -ComputerName $Computer -ScriptBlock {Start-Process "c:\temp\openVPN\openvpn-install-2.4.8-I602-Win7.exe" -ArgumentList "/q" -Wait}
Invoke-Command -ComputerName $Computer -ScriptBlock {Start-Process "c:\temp\openVPN\openvpn-install-2.4.8-I602-Win7.exe" -ArgumentList "/q" -Wait}
但是,我收到了错误
复制项:找不到驱动器。名为“Z”的驱动器不存在。
不胜感激!
【问题讨论】:
-
您可以尝试使用映射驱动器的绝对路径(\\servername\path)而不是驱动器号(Z)
-
就像“复制项目”\\$Computer\z$(15) IT\VPN\openvpn-install-2.4.8-I602-Win7.exe" "\\$Computer\c $\temp\" -递归" ?我尝试过仍然遇到同样的问题@Dexirian
-
如果 Z 指的是映射到另一台计算机上的驱动器,我认为您应该指定映射驱动器的整个路径而不是 Z$。我的 Z 当前映射到 \\server.domain.x\support\devops\tools 所以我会调用 Copy-Item -Source "\\server.domain.x\support\devops\tools\filename" -Destination "\\ $计算机\c$\temp\"
-
是的,我这样做了,但如果我做得正确,请让我仔细检查一下。我转到命令提示符并输入“net use Z:”,这给了我远程名称“\*..*.**\FileStorage”。所以 .. "复制项目 "\*..*.**\FileStorage(15) IT\VPN\openvpn-install-2.4.8-I602-Win7.exe" "\\$计算机\c$\temp\" -Recurse" ?仍然收到相同的错误。 @Dexirian
-
您是否正在与您的用户一起运行脚本?如果您看到驱动器并且没有在提升的提示符下运行,那么您的脚本应该会看到驱动器。如果您使用其他用户运行(例如:通过服务帐户作为计划任务运行)或以管理员身份运行,则可能不会为该用户映射。(无论是“管理员模式”还是其他用户,您可能需要也通过该用户映射驱动器:以管理员身份运行问题的参考:support.microsoft.com/en-ca/help/3035277/…
标签: windows powershell openvpn silent-installer