Invoke-command not not not of请参阅本地网络驱动器

发布于 2025-01-28 01:52:05 字数 1376 浏览 1 评论 0原文

我有两台计算机: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:

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不…忘初心 2025-02-04 01:52:05

powershell远程仅能在系统上下文中映射的默认情况下访问驱动器。最常见的是,这将是基于附带的硬件(无论是USB,SATA,SCSI等)的字母驱动器。

用户上下文中映射的驱动器(例如远程驱动器)没有被映射,因为完整登录的发生方式与您在本地登录的方式没有相同的方式。您可以使用两种解决方法:

  1. 通过SMB/CIFS共享访问文件时使用UNC路径(例如\\ server.domain.tld \ sharename \ sharename \ path \ to \ folder \ or \ files \或\ file .ext

  2. 映射驱动器中的驱动器scriptblock传递给Indoke-command使用 new-psdrive ::

     #单字母驱动名称
    new -psdrive -name“ r” -psprovider filesystem -root“ \\ server.domain.tld \ sharename”
    Get-Childitem R:
    
    #更多描述性驱动器名称
    new -psdrive -name“ remotedrive” -psprovider filesystem -root“ \\ server.domain.tld \ sharename”
    Get-Childitem remotedrive:
     

    要注意的三件事:

    • get-childitem在上面的示例中是要表明,列出新驱动器的内容应显示您希望在远程目录上看到的文件。一旦您确定它对您有用。

      可以省略。

    • 此外,使用较长的驱动器名称为A powershell 功能,并不意味着您可以将共享文件夹映射为具有超过单个字符的文件explorer中的驱动器。

    • 如果您尝试使用与使用invoke-command command使用相同的凭证,则可以遇到双跳问题,试图以这种方式映射到远程驱动器。 正确解决它超出了堆栈溢出的范围,因为这是Active Directory的主要架构考虑

      但是,您可以通过构建凭据对象并将其传递到

      new-psdrivescript> 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:

  1. Use the UNC path when accessing files over an SMB/CIFS share (e.g. \\server.domain.tld\ShareName\Path\To\Folder\Or\file.ext

  2. Map the drive within the ScriptBlock passed to Invoke-Command using New-PSDrive:

    # Single letter drive name
    New-PSDrive -Name "R" -PSProvider FileSystem -Root "\\server.domain.tld\ShareName"
    Get-ChildItem R:
    
    # More descriptive drive name
    New-PSDrive -Name "RemoteDrive" -PSProvider FileSystem -Root "\\server.domain.tld\ShareName"
    Get-ChildItem RemoteDrive:
    

    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 the ScriptBlock, or running Invoke-Command with
      -Authentication CredSSP if your organization does not block it (many do).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文