2016-02-05 74 views
-6

我試圖運行PowerShell命令來獲取所有遠程服務器的所有驅動器的總磁盤空間。當我運行命令時,我得到下面的錯誤。我有一個具有服務器名稱的文本文件,我也確認WinRM已配置並正在運行。嘗試枚舉遠程計算機上的驅動器時出現「訪問被拒絕」錯誤

$Servers = Get-Content "C:\users\anorris\desktop\DR\servers1.txt" 
foreach ($s in $Servers) { 
    Invoke-Command -ComputerName $s {Get-PSDrive} 
} 

錯誤:

[ahv-a2acortst02] Connecting to remote server failed with the following error 
message : Access is denied. 
For more information, see the about_Remote_Troubleshooting Help topic. 
     + CategoryInfo   : OpenError: (:) [], PSRemotingTransportException 
     + FullyQualifiedErrorId : PSSessionStateBroken
+0

該錯誤信息是直線前進。你不這樣做,或該進程沒有,有權訪問驅動器。您是否查看過? –

+0

該錯誤特別提到了['about_Remote_Troubleshooting'](https://technet.microsoft.com/zh-cn/library/hh84 7850.aspx)幫助主題。你看過那個嗎?你的發現是什麼? –

回答

0

一致認爲消息「訪問被拒絕」是你沒有訪問權限的破綻。

我會創建一個憑證變量並確保它是一個擁有遠程系統權限的憑證。 $ Creds = GET-憑證 然後更改您的代碼如下(我加了-ScriptBlock和黑體字

$服務器=獲取內容的「C:\用戶\ anorris \桌面\ DR \ servers1.txt 「 的foreach($ S $中的服務器){ 調用命令-ComputerName $ S -ScriptBlock {GET-PSDrive來} -Credential $ creds }