Powershell:从远程服务器访问共享驱动器 [英] Powershell : Accessing shared drive from remote server

查看:86
本文介绍了Powershell:从远程服务器访问共享驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to access shared drive vai remote server in my Powershell script. My code is below:

$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 会引发以下错误.

When I tried to access shared from Remote Desktop Connection on the server it is working but through powershell it is throwing following error.

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.

I am having Powershell 4 and remote server is windows 2008 R2.

问候,Vj

推荐答案

您是否尝试在本地访问以下路径 \\xxx.xxx.xxx.xxx\netlog\?您拥有访问服务器的凭据.而且你说驱动器是共享的.尝试在本地访问路径.不是通过power-shell.但尝试老式的方式.使用 Run.如果系统提示您输入任何凭据.您可以取消与权限相关的任何问题.如果没有...您尝试访问的文件夹根本没有共享.尝试为其授予所需的权限.如果不是这种情况,请发表评论.

Did you try accessing the following path \\xxx.xxx.xxx.xxx\netlog\ locally? You have the creds to access the server. And also you say the drive is shared. Try accessing the path locally. Not via power-shell. But try the old fashioned way. Using Run. If you are prompted for any credentials to be entered. You may strike off any issues related to permissions. If not... The folder you are trying to access isn't shared at all. Try giving it the required permissions. If this isn't the case please leave a comment.

这篇关于Powershell:从远程服务器访问共享驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆