2

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

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

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

Regards, Vj

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes it is accessible via run from my machine (Where I am running script from) and via remote server also.
1

You might need to enable Multihop Remoting when you access a share from a remote machine and use CredSSP.

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

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

2 Comments

Thanks for your time Jeno. It didn't work. Still throwing same error. While I access to network drive it doesn't require authentication, do you think multihop remoting might be the issue?
I think so. I think you will be authenticated by Kerberos when you access the share even if it can be accessed by Everyone. I think the issue here is not that your user doesn't have access, it is more like the credentials are not passed on to the share access action.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.