繁体   English   中英

Powershell:从远程服务器访问共享驱动器

[英]Powershell : Accessing shared drive from remote server

我正在尝试在Powershell脚本中访问共享驱动器vai远程服务器。 我的代码如下:

$bypass1 = "config"
$bypass2 = "web.config"
$Username = "test\newtest"
$Password = "xxxxxxxxx"
$srv = "xxx.xxx.xxx.xxx"

$securePassword = ConvertTo-SecureString -AsPlainText -Force $Password 
$cred = New-Object System.Management.Automation.PSCredential $Username, $securePassword
$session = New-PSSession -ComputerName $srv -port 22 -Credential $cred
Invoke-Command -Session $session -ScriptBlock {
    $computer = "xxx.xxx.xxx.xxx"
    test-path \\$computer\netlog\php
    Get-ChildItem \\$computer\netlog\
}
Remove-PSSession -Session $session

当我尝试从服务器上的远程桌面连接访问共享时,它正在运行,但是通过Powershell会引发以下错误。

False
Cannot find path '\\xxx.xxx.xxx.xxx\netlog\' because it does not exist.
    + CategoryInfo          : ObjectNotFound: (\\xxx.xxx.xxx.xxx\netlog\:String) [Get-Ch 
   ildItem], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCom 
   mand
    + PSComputerName        : xxx.xxx.xxx.xxx

我有Powershell 4,远程服务器是Windows 2008 R2。

此致Vj

您是否尝试在本地访问以下路径\\\\xxx.xxx.xxx.xxx\\netlog\\ 您具有访问服务器的资格。 另外,您说驱动器是共享的。 尝试在本地访问路径。 不通过电源壳。 但是,请尝试老式的方法。 使用Run 如果提示您输入任何凭据。 您可能会遇到任何与权限有关的问题。 如果没有,则您尝试访问的文件夹根本不共享。 尝试为其提供所需的权限。 如果不是这种情况,请发表评论。

当您从远程计算机访问共享并使用CredSSP时,可能需要启用多跳远程处理。

默认情况下,用于创建远程会话的凭据不会传递到共享访问操作。 我认为每个人至少都会遇到这个问题一次。 :)

http://blogs.technet.com/b/heyscriptingguy/archive/2013/04/04/enabling-multihop-remoting.aspx

http://blogs.technet.com/b/heyscriptingguy/archive/2012/11/14/enable-powershell-quot-second-hop-quot-functionality-with-credssp.aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM