Click here to Skip to main content
13,548,734 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi all
Below is the code i am trying to execute for coping multiple files from one folder to other on remote server but i am getting this error

PS C:\Windows> D:\ScriptRepo\Smart_Backup_Create folders_by_Date.ps1
Hit Line breakpoint on 'D:\ScriptRepo\Smart_Backup_Create folders_by_Date.ps1:5'
[DBG]: PS C:\Windows>> 
\\$ComputerName\$DriveLetter$\BMCSoftware\BMCPortalKit\webserver\tools\apache-openssl\logs : The term 
'\\$ComputerName\$DriveLetter$\BMCSoftware\BMCPortalKit\webserver\tools\apache-openssl\logs' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the 
spelling of the name, or if a path was included, verify that the path is correct and try again.
At D:\ScriptRepo\Smart_Backup_Create folders_by_Date.ps1:5 char:12
+ $SrcPath = \\$ComputerName\$DriveLetter$\BMCSoftware\BMCPortalKit\webserver\tool ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (\\$ComputerName...he-openssl\logs:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
[DBG]: PS C:\Windows>> 
\\$ComputerName\$DriveLetter$\Log_Backup_$((Get-Date).ToString('yyyy-MM-dd')) : The term '\\$ComputerName\$DriveLetter$\Log_Backup_$((Get-Date).ToString('yyyy-MM-dd'))' is not recognized as 
the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At D:\ScriptRepo\Smart_Backup_Create folders_by_Date.ps1:6 char:13
+ $DestPath = \\$ComputerName\$DriveLetter$\Log_Backup_$((Get-Date).ToString('yyyy ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (\\$ComputerName...('yyyy-MM-dd')):String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
[DBG]: PS C:\Windows>> 


    Directory: \\USDC1-BEMAPDC01\D$


Mode                LastWriteTime     Length Name                                                                                                                                             
----                -------------     ------ ----                                                                                                                                             
d----         8/14/2017   5:35 AM            Log_Backup_2017-08-14                                                                                                                            
[DBG]: PS C:\Windows>> 
Copy-Item : Cannot find path 'D:\BMCSoftware\BMCPortalKit\webserver\tools\apache-openssl\logs' because it does not exist.
At D:\ScriptRepo\Smart_Backup_Create folders_by_Date.ps1:8 char:1
+ Copy-Item -Recurse -Filter *.* -path $SrcPath -destination $DestPath -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (D:\BMCSoftware\...he-openssl\logs:String) [Copy-Item], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand


Please let me know where i am doing wrong. Both the source and destination folders are in same server

What I have tried:

$ComputerName = "ServerName"
$DriveLetter = "D"
$CreateFolderPath = "Log_Backup_$((Get-Date).ToString('yyyy-MM-dd'))"

$SrcPath = \\$ComputerName\$DriveLetter$\BMCSoftware\BMCPortalKit\webserver\tools\apache-openssl\logs
$DestPath = \\$ComputerName\$DriveLetter$\Log_Backup_$((Get-Date).ToString('yyyy-MM-dd'))
New-Item -Path \\$ComputerName\$DriveLetter$\$Path -type directory -Force // Creating folder
Copy-Item -Recurse -Filter *.* -path $SrcPath -destination $DestPath -Force
Posted 13-Aug-17 23:45pm
Comments
User-2223753 14-Aug-17 6:09am
   
Enclose the variable content with double quotes:
$SrcPath = "\\$ComputerName\$DriveLetter ..."

Do that too when passing as arguments (they may contain spaces which would get the string treated as multiple arguments)
Copy-Item -path "$SrcPath"


You might get still problems with
"Log_Backup_$((Get-Date).ToString('yyyy-MM-dd'))"
Solving that requires knowing what that should do.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web01 | 2.8.180515.1 | Last Updated 14 Aug 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100