0

I am trying to copy file from my local machine to a server destination

My Script: Copy-Item –Path D:\Test.txt –Destination '\\10.10.X.X\c$'

Error:

Copy-Item : The network path was not found At D:\PS_Test_script.ps1:1 char:2 + Copy-Item –Path D:\Test.txt –Destination '\\10.10.X.28X\c$' + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Copy-Item], IOException + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.CopyItemCommand 

The server has credentials, I am guessing that, I have to invoke something to use the credentials.

11
  • 1
    stackoverflow.com/a/65972741/11954025 Commented Jun 13, 2021 at 7:32
  • Thanks @Daniel. Please give me idea of encryptedCred. What does it contain and in what format? Commented Jun 13, 2021 at 7:56
  • I think you would get a different message if the credentials are incorrect. Are you able to ping the ip address? Commented Jun 13, 2021 at 10:52
  • Yes, I am able to ping that @iRon Commented Jun 13, 2021 at 10:54
  • 1
    Ok, that is a complete different message suggesting that I was right and the credentials aren't the issue... Or? Commented Jun 13, 2021 at 11:33

2 Answers 2

1

To keep it somewhat simple, to copy to a folder share which requires different credentials to access you can use New-PSDrive to map a drive using those credentials

$desiredMappedDrive = 'J' $desiredMappedDrivePath = '\\10.10.X.X\c$' # Map to administrative C: drive share requires administrator credentials) $source = 'D:\Test.txt' $destination = "${desiredMappedDrive}:\temp" # Get-Credential cmdlet will request that you enter a username and password that has access to the share New-PSDrive -Name $desiredMappedDrive -PSProvider FileSystem -Root $desiredMappedDrivePath -Credential (Get-Credential) # after drive is mapped copy file over Copy-Item -Path $source -Destination $destination -Verbose 
Sign up to request clarification or add additional context in comments.

1 Comment

the error shows: New-PSDrive : The network path was not found
0

Here is a whole different approach using PSSession no need to map any drives:

$targetComputerName = "127.0.0.1" $Session = New-PSSession $targetComputerName -Credential 'username' $DestinationPath = "C:\temp" $source = 'D:\Test.txt' Copy-Item -Path $source -ToSession $Session -Destination $DestinationPath $Session | Remove-PSSession 

If you want to execute it as a script you would have to create a [SecureString] and build a credential object.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.