How to Fix “FileSystem Provider Supports Credentials Only on New-PSDrive” Error When Copying Files Remotely in PowerShell


2 views

When attempting to use Copy-Item with credentials to transfer files to a remote server's administrative share (C$), PowerShell throws this frustrating error:

The FileSystem provider supports credentials only on the New-PSDrive cmdlet.
Perform the operation again without specifying credentials.

PowerShell's FileSystem provider has a fundamental limitation - it doesn't support credential parameters for direct file operations. This is by design for security reasons. However, there are several workarounds that give you the same functionality.

Method 1: Mapping a Temporary Network Drive

The most reliable approach is to create a PSDrive with credentials:

$Source = "C:\folder1"
$DestPath = "\\172.22.0.115\c$\folder2\"
$DriveLetter = "Z"

# Create credential object
$Password = ConvertTo-SecureString -AsPlainText -Force -String "MyPassword"
$User = "Domain\Administrator"
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user,$password

# Map drive
New-PSDrive -Name $DriveLetter -PSProvider FileSystem -Root $DestPath -Credential $credentials -Persist:$false

# Perform copy
Copy-Item -Path $Source -Destination "${DriveLetter}:\" -Recurse -Force

# Clean up
Remove-PSDrive -Name $DriveLetter

Method 2: Using BITS Transfer (Alternative Approach)

While your BITS attempt failed, here's the correct implementation:

Start-BitsTransfer -Source $Source -Destination $DestPath 
    -Credential $credentials -TransferType Upload -Priority High

Note: BITS has file size limitations (default 500MB) which can be adjusted via Group Policy.

Method 3: Robocopy with Net Use

Though Robocopy itself doesn't accept credentials, you can combine it with net use:

net use \\172.22.0.115\c$ /user:Domain\Administrator MyPassword
robocopy C:\folder1 \\172.22.0.115\c$\folder2 /E /ZB /R:3 /W:5 /LOG:C:\copy.log
net use \\172.22.0.115\c$ /delete

1. Never store plaintext passwords in scripts - use Get-Credential for interactive sessions
2. Consider using constrained endpoints (JEA) for production environments
3. For automated processes, use managed service accounts or certificate-based authentication

For large file transfers:
- Add -Parallel parameter in PowerShell 7+
- Use /MT switch with Robocopy for multi-threaded copies
- Consider /COMPRESS flag for WAN transfers
- Pre-calculate total size with Measure-Object to estimate transfer time


Many PowerShell users encounter this frustrating limitation: The FileSystem provider simply doesn't support credentials directly with Copy-Item. The error message clearly states this restriction, but doesn't offer practical solutions. Let's explore why this happens and how to work around it effectively.

The FileSystem provider expects credential authentication to happen at the drive mapping level. Here's the proper approach:

# Create temporary mapped drive with credentials
$Source = "C:\folder1"
$RemotePath = "\\172.22.0.115\c$\folder2\"
$DriveLetter = "Z" # Choose an available letter

$Password = ConvertTo-SecureString -AsPlainText -Force -String "MyPassword"
$User = "Domain\Administrator"
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user,$password

# Map the drive
New-PSDrive -Name $DriveLetter -PSProvider FileSystem -Root $RemotePath -Credential $credentials -Persist:$false

# Now copy using the mapped drive
Copy-Item -Path $Source -Destination "${DriveLetter}:\" -Recurse

# Clean up
Remove-PSDrive -Name $DriveLetter

While New-PSDrive is the most straightforward solution, here are other approaches depending on your environment:

Using Robocopy with Runas

# Save credentials securely first
cmdkey /add:172.22.0.115 /user:Domain\Administrator /pass:MyPassword

# Then run robocopy
robocopy C:\folder1 \\172.22.0.115\c$\folder2 /mir /r:1 /w:1

PowerShell Sessions (For Modern Versions)

$session = New-PSSession -ComputerName 172.22.0.115 -Credential $credentials
Copy-Item -Path $Source -Destination C:\folder2 -ToSession $session -Recurse
Remove-PSSession $session

When working with credentials:

  • Never store passwords in plain text scripts
  • Consider using Export-Clixml/Import-Clixml for credential persistence
  • Use the minimum required permissions
  • Clean up temporary drives/sessions properly

For production environments, you might want to create a dedicated function that handles all this logic while properly managing errors and cleanup.