Access to the Path Is Denied in PowerShell

  1. an Overview of PowerShell
  2. Access to the Path Is Denied in PowerShell
  3. Reason for Access to the Path Is Denied
  4. Solution to Fix the Access to the Path Is Denied Error

This article shows how to comprehend the issue that we often experience, that access to the path is denied, and how to overcome it using the PowerShell program.

We will discuss the PowerShell security and file access issues and learn about a solution to this problem. But, first, let’s look at the error we receive.

an Overview of PowerShell

PowerShell combines a command-line shell, scripting language, and configuration management framework into a single, cross-platform tool for automating routine tasks. PowerShell is cross-platform, functioning on Windows, Linux, and macOS.

PowerShell is a modern command shell incorporating the most useful features in other well-known shells. For example, PowerShell can accept and return.NET objects compared to most shells that can only receive and return text.

Access to the Path Is Denied in PowerShell

When using PowerShell, if we try to execute a script from the console that contains the following code as an example:

$inpath = "C:\users\xxxxx\path\foo\bar"

We will get the error something below as a result:

Get-Content : Access to the path 'C:\users\xxxxx\path\foo\bar' is denied.

Reason for Access to the Path Is Denied

The error often occurs in Windows PowerShell and other applications.

  • This error warns you are not authorized to examine the specified file or folder. It is because the user account you are now logged into on your computer has not been allowed access to the system by your system administrator.
  • There is also the possibility that the access was blocked by a third-party program you use.
  • To clarify, you are attempting to access files, directories, and paths while logged in to an illegal account.

Solution to Fix the Access to the Path Is Denied Error

While doing certain activities, such as accessing, relocating, copying, or deleting files and directories, the Access denied appears. Below we’ll discuss a way to overcome this error.

Change Account Status to Administrator

Making your user account the administrator is the solution to most occurrences of this error. The following is the procedure for changing your account to admin status:

  • In the windows search bar, type Run.
  • Write control userpasswords2 in Run and click on OK.
  • In the new window that opens, choose your profile and then click on Properties.
  • Now choose the Group Membership tab, select Administrator, click on Apply, and then OK.

In addition, you have the option of disabling your additional antivirus software for the time being.

Related Article - PowerShell Path

  • Split Directory Path in PowerShell
  • Path With Spaces in PowerShell
  • Join Path to Combine More Than Two Strings Into a File Path in PowerShell