1

I launched a couple servers in AWS and I want to read the contents of the a file using Powershell.

On server 1 I create a file called App_configuration.txt and placed in the root of c:\.

The file has just 2 lines in it:

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

I'm trying to access the file with this command using the remote IP of the server. The xx.xxx.xx.xxx is supposed to be the remote 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

I can RDP into the remote server and list the file:

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


    Directory: C:\


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

I am not the same user on my local machine as the one that can log into the remote machine. The server I am trying to access is in AWS, and I am trying to access it from my local machine.

I have the powershell port 5985 open on the AWS security group (firewall) and I can connect to it remotely using telnet.

Why can't I read this remote file with this powershell line? I think the issue might be network related.

7
  • Have you tried to mount `\\xx.xxx.xx.xxx\c$` as a network drive? If you are able to do that then the problem is a syntax problem.
    – Ramhound
    Mar 5, 2021 at 19:38
  • @TimDunphy If you do go to \\xx.xxx.xx.xxx\c$\ on the machine you run the PowerShell from, are you able to open that file and read from it that way? You will need that level of access or to enter a credential to authenticate to that resource and then run the command. You can also consider running invoke-command and running the process that way from the local file system path and not the hidden C$ admin share. I can think of a few ways to tackle this process depending on your configuration and authentication hop needs, and so forth. Mar 7, 2021 at 4:02
  • @DrinkMorePimpJuiceIT No, I am trying to open a file in AWS from my local machine. If I try to do that I get the error I show in the OP. I can log into the AWS machine and access the file from both the c$ share and the local file system: `c:` no problem. Thanks for your help!
    – Tim Dunphy
    Mar 7, 2021 at 23:55
  • The AWS system is running on Windows Server 2019 or what OS? You have to allow file and print sharing through the Windows FW for \\ipaddress\c$ to be accessible. Furthermore, the credential you authenticate against the \\ipaddress\c$ "remotely" but be a local administrator on the AWS server. With those two things, you should be able to access the Windows C$ hidden admin share no problem remotely. Otherwise, you'd need to authenticate and/or open the protocol/ports to be allowable inbound for the network zone from the OS perspective. Using invoke-command may be better than C$ for you tho Mar 8, 2021 at 13:17
  • 1
    @DrinkMorePimpJuiceIT busy day, I'll try to get to this later today or tomorrow. Thanks again for your help.
    – Tim Dunphy
    Mar 9, 2021 at 23:00

1 Answer 1

1

Use Invoke-Command and run Get-Content command from within it since you have port 5985 open.

Otherwise allow SMB: File and print sharing or applicable TCP ports through your Windows Firewall.

PowerShell Remote Invoke-Command

Invoke-Command -ComputerName <IP Address> -ScriptBlock { Process {
    Get-Content -Path "C:\App_configuration.txt"
    }
};

PowerShell Remote Invoke-Command (with credential)

$cred = Get-Credential "domain\administrator" 

Invoke-Command -ComputerName <IP Address> -ScriptBlock { Process {
    Get-Content -Path "C:\App_configuration.txt"
    }
} -AsJob -Credential $cred;  

Supporting Resources

  • Enable-PSRemoting

  • Invoke-Command

    -ScriptBlock scriptblock

    The commands to run.

    Enclose the commands in curly braces { } to create a script block. This parameter is required.

  • Internet firewalls can prevent browsing and file sharing

    Microsoft file sharing SMB: User Datagram Protocol (UDP) ports from 135 through 139 and Transmission Control Protocol (TCP) ports from 135 through 139. Direct-hosted SMB traffic without a network basic input/output system (NetBIOS): port 445 (TCP and UPD).

1
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – DavidPostill
    Mar 9, 2021 at 18:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .