Copy-item Access is Denied in PowerShell: 8 Tested Fixes

This issue is due to lack of NTFS write permissions

Reading time icon 4 min. read


Readers help support Windows Report. We may get a commission if you buy through our links. Tooltip Icon

Read our disclosure page to find out how can you help Windows Report sustain the editorial team Read more

How to fix the Copy-Item Access is denied in PowerShell

Running into the Copy-Item Access is Denied error in PowerShell is baffling since you can perform the process in File Explorer without a problem. This is due to lack of NTFS permissions when writing to a network share but the solutions below will fix the problem in no time.

How do I fix the Copy-Item Access is Denied error in PowerShell?

1. Ensure correct NTFS permissions

  1. Press Win + E to start File Explorer.
  2. Navigate to the folder you want to modify.
  3. Right-click on the folder and select Properties.
  4. Click on the Security tab.
  5. Click the Edit button to change permissions.
  6. Ensure your user account or the account running the PowerShell script has Full Control permissions.
  7. Click Apply and then OK to save the changes.

Ensuring proper NTFS permissions allows the script to write to the folder, resolving access issues.

2. Verify the Share permissions

  1. Open the Run dialog by pressing Win + R, type fsmgmt.msc, and press Enter.
  2. Navigate to the shared folder.
  3. Right-click on the folder and select Properties.
  4. Click on the Share Permissions tab.
  5. Ensure that the user or group running the PowerShell script has Full Control permissions.
  6. Click Apply and then OK.

Both NTFS and Share permissions need to allow write access for successful file copying.

3. Run PowerShell as Administrator

  1. Click on the Start button.
  2. Type PowerShell in the search bar.
  3. Right-click on Windows PowerShell and select Run as administrator.
  4. Execute your Copy-Item script again.

Running PowerShell as an administrator ensures full access to protected system folders and network shares.

4. Use UNC paths without credentials

  1. Create a new PowerShell drive for the network location using New-PSDrive: New-PSDrive -Name "P" -PSProvider FileSystem -Root "\\network\path" -Persist
  2. Use the new drive letter to execute Copy-Item (change the source and destination paths accordingly): Copy-Item "P:\source\file" -Destination "P:\destination\path"

Using UNC paths and mapping a network drive helps avoid credential-related issues with network paths.

5. Modify Environment Variables in PowerShell

  1. Replace environment variables with PowerShell syntax: Copy-Item -Path "E:\FolderA" -Destination "C:\Users\$($env:USERNAME)\AppData\Roaming\FolderB" -Recurse -Force
  2. Alternatively, use the APPDATA environment variable directly: Copy-Item -Path "E:\FolderA" -Destination "$($env:APPDATA)\FolderB" -Recurse -Force

Correctly referencing environment variables in PowerShell ensures paths are resolved properly.

6. Enable PowerShell Remoting

  1. On the remote machine, run: Enable-PSRemoting -Force
  2. Ensure the user has permission to run scripts on the remote machine: Set-PSSessionConfiguration -ShowSecurityDescriptorUI -Name Microsoft.PowerShell
  3. Use the ToSession parameter for remote copying: $session = New-PSSession -ComputerName "remote_machine" -Credential "username" $source = "C:\path\to\source" $dest = "C:\path\to\destination" Copy-Item -Path $source -Destination $dest -ToSession $session -Recurse -Force

Enabling PowerShell remoting and using the correct session parameters makes remote file operations smoother.

7. Address User Account Control (UAC) issues

  1. Create a PowerShell script to elevate permissions: If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell -Verb runAs -ArgumentList $MyInvocation.MyCommand.Definition Break }
  2. Execute the Copy-Item command within the elevated session: Copy-Item "C:\source\file" -Destination "C:\Program Files (x86)\target\folder" -Force

Elevating permissions within the script circumvents UAC restrictions.

8. Handle the Double Hop issue

  1. Pre-copy necessary files to the remote machine: Copy-Item -Path "C:\local\path\file" -Destination "\\remote_machine\path" -Force
  2. Use Invoke-Command to run the installation on the remote machine: Invoke-Command -ComputerName "remote_machine" -ScriptBlock { Copy-Item -Path "\\remote_machine\path\file" -Destination "C:\Windows\Temp" -Force Start-Process msiexec -ArgumentList "/i C:\Windows\Temp\installer.msi /quiet" -Wait }

Pre-copying files and using direct paths prevent issues related to multiple remote connections.

By following these solutions, you should be able to resolve the Copy-Item: Access is denied error in PowerShell.

Once this error is cleared out, you may also check our guide on what to do if PoweShell is not showing the full output.

Also, if PowerShell is closing after running a script, click the highlighted link to learn how to keep it open.

For any suggestions or question, hit the comments section below to write them down.

More about the topics: PowerShell