Invoke-command not not not of请参阅本地网络驱动器
我有两台计算机:A和B。我正在尝试自动化一些CI \ CD任务,而我的任务是远程启动B上的某个过程。.exe文件本身位于r 驱动器,这是本地网络驱动器。因此,我这样做:
# here $cred has encrypted credentials, but it is off topic...
Invoke-Command -ComputerName B -Credential $cred -ScriptBlock {
R:\WebClient\Platform\UP_110\Proc.exe
}
因此,显然,这与r:\ webclient \ up_110 \ proc.exe
在B的PowerShell和命中输入中一样。
现在的问题是,在A上运行上述代码时,我会遇到此错误:
The term 'R:\WebClient\Platform\UP_110\Proc.exe' is not recognized as the name of a cmdlet, function, sc
ript file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is corr
ect and try again.
+ CategoryInfo : ObjectNotFound: (R:\WebClient\Pl...IMS.UP.Host.exe:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
+ PSComputerName : B
显然说没有r:\ webclient \ platform \ up_110 \ proc.exe
的文件。 。但这不是真的。我确实有:
作为事实,我在A和B上都有此R驱动器。
如果我将.EXE移至c下的任何目录,则代码正常工作
驱动器(这是我的系统磁盘),但不是r
。 现在甚至有趣的是,我可以在A和B上手动运行r:\ webclient \ up_110 \ proc.exe
。而且有效。
那么我面临的问题是什么?谢谢。
I have two computers: A and B. I'm trying to automate some CI\CD tasks, and my task is to start some process on B remotely, from A. The .exe file itself is on the R
drive, which is a local network drive. So I do this:
# here $cred has encrypted credentials, but it is off topic...
Invoke-Command -ComputerName B -Credential $cred -ScriptBlock {
R:\WebClient\Platform\UP_110\Proc.exe
}
So apparently this would be the same thing as typing R:\WebClient\Platform\UP_110\Proc.exe
on B's PowerShell and hitting Enter.
Now the problem is that I get this error when running the above code on A:
The term 'R:\WebClient\Platform\UP_110\Proc.exe' is not recognized as the name of a cmdlet, function, sc
ript file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is corr
ect and try again.
+ CategoryInfo : ObjectNotFound: (R:\WebClient\Pl...IMS.UP.Host.exe:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
+ PSComputerName : B
Apparently it says that there is no such file as R:\WebClient\Platform\UP_110\Proc.exe
on my B computer. But that is not true. I do have it:
As a matter of a fact, I have this R drive both on A and B.
The code works fine if I move the .exe to any directory under the C
drive (which is the system disk for me), but not for R
.
Now even funnier is that I can run R:\WebClient\Platform\UP_110\Proc.exe
on A and B manually. And it works.
So what's the issue here I'm facing? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
powershell远程仅能在系统上下文中映射的默认情况下访问驱动器。最常见的是,这将是基于附带的硬件(无论是USB,SATA,SCSI等)的字母驱动器。
在用户上下文中映射的驱动器(例如远程驱动器)没有被映射,因为完整登录的发生方式与您在本地登录的方式没有相同的方式。您可以使用两种解决方法:
通过SMB/CIFS共享访问文件时使用UNC路径(例如
\\ server.domain.tld \ sharename \ sharename \ path \ to \ folder \ or \ files \或\ file .ext
映射驱动器中的驱动器
scriptblock
将传递给Indoke-command
使用
::new-psdrive
要注意的三件事:
get-childitem
在上面的示例中是要表明,列出新驱动器的内容应显示您希望在远程目录上看到的文件。一旦您确定它对您有用。可以省略。
此外,使用较长的驱动器名称为A powershell 功能,并不意味着您可以将共享文件夹映射为具有超过单个字符的文件explorer中的驱动器。
如果您尝试使用与使用
invoke-command command
使用相同的凭证,则可以遇到双跳问题,试图以这种方式映射到远程驱动器。 正确解决它超出了堆栈溢出的范围,因为这是Active Directory的主要架构考虑。但是,您可以通过构建凭据对象并将其传递到
new-psdrive
从script> scriptblock
中运行。 ,或运行-authentication credssp
如果您的组织不阻止它(许多人)。PowerShell Remoting can only access drives by default that are mapped within the system context. Most commonly, this will be letter drives based on attached hardware (whether this be USB, SATA, SCSI, etc.).
Drives mapped in the user context, such as remote drives, are not mapped because a full logon does not occur the same way as if you log in locally. There are two workarounds you have at your disposal:
Use the UNC path when accessing files over an SMB/CIFS share (e.g.
\\server.domain.tld\ShareName\Path\To\Folder\Or\file.ext
Map the drive within the
ScriptBlock
passed toInvoke-Command
usingNew-PSDrive
:Three things to note:
Get-ChildItem
in the example above is to show that listing the contents of the new drives should show the files you expect to see at the remote directory. This can be omitted once you are sure it works for you.Additionally, using a longer drive name is a PowerShell feature and does not mean that you can map shared folders as a drive from within File Explorer with more than a single character.
You may run into the double hop issue trying to map to a remote drive this way, if you are attempting to use the same credential you initiated
Invoke-Command
with. Solving it properly is beyond the scope of Stack Overflow as this is a major architectural consideration for Active Directory.However, you can work around it by building the credential object and passing it to
New-PSDrive
from within theScriptBlock
, or runningInvoke-Command
with-Authentication CredSSP
if your organization does not block it (many do).