Get-Content permissions error

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 10 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
sekou2331
Posts: 318
Last visit: Sat Oct 28, 2023 7:46 am

Get-Content permissions error

Post by sekou2331 »

This may be a noob question but has anyone have an issue when trying to use get-content on remote computer through UNC.I am admin of all computers on my network. Also i can access the same UNC path through Explorer.

\\computername\C$\username\
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Get-Content permissions error

Post by jvierra »

What is the error and what kind of content are you trying to get?
User avatar
sekou2331
Posts: 318
Last visit: Sat Oct 28, 2023 7:46 am

Re: Get-Content permissions error

Post by sekou2331 »

Anything under the users profile. The funny thing is I can use copyItem on the same path to another computers path and it works

Get-Content : Access to the path '\\Computername\c$\Users\Username' is denied.
At line:1 char:1
+ Get-Content "\\Computername\c$\Users\Username"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (\\Computername\c$\Users\Username:String) [Get-Content], UnauthorizedAccessExceptio
n
+ FullyQualifiedErrorId : GetContentReaderUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetContentCommand
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Get-Content permissions error

Post by jvierra »

Get-Content opens files and not folders.

You must specify a file name.

This is not a correct file name: \Computernamec$UsersUsername

Start by reading up in how to use UNC paths.
User avatar
livefortechnology
Posts: 23
Last visit: Sun Feb 27, 2022 12:39 am

Re: Get-Content permissions error

Post by livefortechnology »

I've never been able to get Get-content to work via UNC so I don't think the op is crazy (nor did his string look anything like what was quoted - his UNC looks correct).

Okay gurus, so what's a working one-liner to get-content from a unc-based file path that works?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Get-Content permissions error

Post by jvierra »

I have many domains WWS2003,WS2008,WS2008R2,WS2012. All domains and all OS types -XP/7/8 are able to use Get-Content with a UNC. I have numerous scripts that retrieve information from log files using this method. It has always worked.

Perhaps you have firewall issues or trust issues.

The UNC posted by the original OP was pointed at a folder. Look closely and think about what that UNC is:

"\Computernamec$UsersUsername"
This is bad UNC all the way. It is missing a leading '\' and is missing other '\' characters. I suspect it should be:
"\\Computername\c$\Users\Username"
This would also be a bad UNC for a file as it points to a folder.

Even if it were a file the users\username folder on Vista and later do not allow admin access by default. You must explicitly request to have the admin added to the permissions. If you browse the folder with Explorer from the machine you will be asked if you want to give administrators access. When you answer yes the permissions are permanently altered to allow admin access.

Understanding how these things work is the purpose of MCP certification. It is always worthwhile to, at a minimum, get the course book and read it. You will learn much about each new OS that MS produces.

With all of this inmind go back and try to access a simple file over a UNC. Start by creating a folder you know you have access to and place a text file in the folder. Be sure you can see the file on the UNC via this:

dir \\computer\c$\temp\test.txt
If that works then do this:

Get-Content \\computer\c$\temp\test.txt

If that fails then turn off the firewall on the remote machine and try again.

If that fails still then place a support call with Microsoft as you have a bad system or a bad configuration.
This topic is 10 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked