I am trying to access shared drive vai remote server in my Powershell script. My code is below:
我试图在我的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
When I tried to access shared from Remote Desktop Connection on the server it is working but through powershell it is throwing following error.
当我尝试从服务器上的远程桌面连接访问共享时它正在工作但是通过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
I am having Powershell 4 and remote server is windows 2008 R2.
我有Powershell 4,远程服务器是Windows 2008 R2。
Regards, Vj
2 个解决方案
#1
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.
您是否尝试在本地访问以下路径\\ xxx.xxx.xxx.xxx \ netlog \?您有信心访问服务器。而且你也说驱动器是共享的。尝试在本地访问路径。不是通过power-shell。但尝试老式的方式。使用Run。如果系统提示您输入任何凭据。您可以删除与权限相关的任何问题。如果不是...您尝试访问的文件夹根本不共享。尝试给它所需的权限。如果不是这种情况,请发表评论。
#2
You might need to enable Multihop Remoting when you access a share from a remote machine and use CredSSP.
从远程计算机访问共享并使用CredSSP时,可能需要启用Multihop Remoting。
The credentials you use to create the remote session are not passed to the share access action by default. I think everyone runs into this problem at least once. :)
默认情况下,用于创建远程会话的凭据不会传递给共享访问操作。我想每个人都至少遇到过这个问题一次。 :)
http://blogs.technet.com/b/heyscriptingguy/archive/2013/04/04/enabling-multihop-remoting.aspx
#1
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.
您是否尝试在本地访问以下路径\\ xxx.xxx.xxx.xxx \ netlog \?您有信心访问服务器。而且你也说驱动器是共享的。尝试在本地访问路径。不是通过power-shell。但尝试老式的方式。使用Run。如果系统提示您输入任何凭据。您可以删除与权限相关的任何问题。如果不是...您尝试访问的文件夹根本不共享。尝试给它所需的权限。如果不是这种情况,请发表评论。
#2
You might need to enable Multihop Remoting when you access a share from a remote machine and use CredSSP.
从远程计算机访问共享并使用CredSSP时,可能需要启用Multihop Remoting。
The credentials you use to create the remote session are not passed to the share access action by default. I think everyone runs into this problem at least once. :)
默认情况下,用于创建远程会话的凭据不会传递给共享访问操作。我想每个人都至少遇到过这个问题一次。 :)
http://blogs.technet.com/b/heyscriptingguy/archive/2013/04/04/enabling-multihop-remoting.aspx