簡體   English   中英

為什么我不能在 Powershell 的遠程服務器上讀取此文件?

[英]Why can't I read this file on a remote server in Powershell?

我在 AWS 中啟動了幾台服務器,我想使用 Powershell 讀取文件的內容。

在服務器 1 上,我創建了一個名為App_configuration.txt的文件,並將其放在c:\的根目錄中。

該文件只有 2 行:

<Path>C:\GoodToGo</Path>
<Path>C:\GoodToGo2</Path>

我正在嘗試使用服務器的遠程 IP 使用此命令訪問該文件。 xx.xxx.xx.xxx應該是遠程 IP:

Get-Content -Path "\\xx.xxx.xx.xxx\c$\App_configuration.txt"
Get-Content : Cannot find path '\\xx.xxx.xx.xxx\c$\App_configuration.txt' because it does not exist.
At line:1 char:1
+ Get-Content -Path "\\xx.xxx.xx.xxx\c$\App_configuration.txt"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (\\xx.xxx.xx.xxx\c$\App_configuration.txt:String) [Get-Content], ItemNot
   FoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand

我可以 RDP 進入遠程服務器並列出文件:

PS C:\> ls C:\App_configuration.txt


    Directory: C:\


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----         3/2/2021   4:12 PM             51 App_configuration.txt

我在本地計算機上的用戶與可以登錄遠程計算機的用戶不同。 我嘗試訪問的服務器位於 AWS 中,我嘗試從本地計算機訪問它。

為什么我不能用這個 powershell 行讀取這個遠程文件?

PowerShell 似乎無法訪問指定位置的文件。 因此,首先驗證該文件是否存在並且可以訪問。

Test-Path "\\xx.xxx.xx.xxx\c$\App_configuration.txt"

如果Test-Path無法返回 True,則無法找到文件或用戶無權從服務器獲取文件。 在找到文件之前,使用Get-Content是沒有意義的。

上次我遇到同樣的問題時,也是經典的 Kerberos 委托/雙跳問題。 它無法枚舉路徑,因為它無法委派您的憑據,所以這是我首先要檢查的。 嘗試使用相同的方法僅連接到計算機的根目錄 - 我希望您會收到憑據錯誤。

如果您能夠通過為第二個躍點啟用 CredSSP 來解決此問題。

好的,如果你試試這個會發生什么:

$server="xx.xxx.xx.xxx"
$user="$server\your_User_on_xx.xxx.xx.xxx"
$passw=ConvertTo-SecureString 'your_password_on_xx.xxx.xx.xxx' -AsPlainText -Force
$cred=New-Object System.Management.Automation.PSCredential($user,$passw)

icm $server {cat "C:\App_configuration.txt"} -Credential $cred

您需要在服務器 1 上為 C 的根創建訪問權限,這不是默認設置。

要僅授予對 root 的訪問權限,請從管理員帳戶運行此命令:

ICACLS "C:\" /grant:r "Authenticated Users"

如果要授予對整個驅動器的訪問權限,請使用:

ICACLS "C:\" /inheritance:e /grant:r "Authenticated Users"

只要您啟用了 powershell 遠程處理,“Authenticated Users”組應該包括 powershell 遠程用戶,根據錯誤消息顯示。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM