Copy-item Access is Denied in PowerShell: 8 Tested Fixes
This issue is due to lack of NTFS write permissions
4 min. read
Published on
Read our disclosure page to find out how can you help Windows Report sustain the editorial team. Read more
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
- Press Win + E to start File Explorer.
- Navigate to the folder you want to modify.
- Right-click on the folder and select Properties.
- Click on the Security tab.
- Click the Edit button to change permissions.
- Ensure your user account or the account running the PowerShell script has Full Control permissions.
- 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
- Open the Run dialog by pressing Win + R, type fsmgmt.msc, and press Enter.
- Navigate to the shared folder.
- Right-click on the folder and select Properties.
- Click on the Share Permissions tab.
- Ensure that the user or group running the PowerShell script has Full Control permissions.
- Click Apply and then OK.
Both NTFS and Share permissions need to allow write access for successful file copying.
3. Run PowerShell as Administrator
- Click on the Start button.
- Type PowerShell in the search bar.
- Right-click on Windows PowerShell and select Run as administrator.
- 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
- Create a new PowerShell drive for the network location using New-PSDrive:
New-PSDrive -Name "P" -PSProvider FileSystem -Root "\\network\path" -Persist
- 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
- Replace environment variables with PowerShell syntax:
Copy-Item -Path "E:\FolderA" -Destination "C:\Users\$($env:USERNAME)\AppData\Roaming\FolderB" -Recurse -Force
- 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
- On the remote machine, run:
Enable-PSRemoting -Force
- Ensure the user has permission to run scripts on the remote machine:
Set-PSSessionConfiguration -ShowSecurityDescriptorUI -Name Microsoft.PowerShell
- 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
- 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 }
- 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
- Pre-copy necessary files to the remote machine:
Copy-Item -Path "C:\local\path\file" -Destination "\\remote_machine\path" -Force
- 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.
User forum
0 messages