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\
Get-Content permissions error
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.
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.
Re: Get-Content permissions error
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
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
Re: Get-Content permissions error
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.
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.
- livefortechnology
- Posts: 23
- Last visit: Sun Feb 27, 2022 12:39 am
Re: Get-Content permissions error
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?
Okay gurus, so what's a working one-liner to get-content from a unc-based file path that works?
Re: Get-Content permissions error
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.
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.