2015-05-08 96 views
1

我想在我的Powershell腳本中訪問共享驅動器遠程服務器。我的代碼如下:Powershell:從遠程服務器訪問共享驅動器

$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

回答

1

你嘗試訪問本地下面的路徑\\xxx.xxx.xxx.xxx\netlog\?您有權訪問服務器。而且你也說驅動器是共享的。嘗試在本地訪問路徑。不通過電源外殼。但嘗試老式的方式。使用Run。如果系統提示您輸入任何憑據。您可以刪除任何與權限相關的問題。如果沒有...您試圖訪問的文件夾根本不共享。嘗試給它所需的權限。如果不是這種情況,請發表評論。

+0

是的,它是通過從我的機器運行訪問(如果我運行從腳本),並通過遠程服務器也。 – Vijay

0

當您從遠程計算機訪問共享並使用CredSSP時,可能需要啓用Multihop Remoting。

默認情況下,用於創建遠程會話的憑據不會傳遞給共享訪問操作。我認爲每個人都會遇到這個問題至少一次。 :)

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

+0

謝謝你的時間Jeno。它沒有工作。仍然拋出相同的錯誤。雖然我訪問網絡驅動器時不需要身份驗證,但您認爲多跳遠程可能是問題嗎? – Vijay

+0

我這麼認爲。我認爲當您訪問共享時,Kerberos即使可以被Everyone訪問,也會對其進行身份驗證。我認爲這裏的問題不是你的用戶沒有訪問權限,更像是證書沒有傳遞給共享訪問操作。 –