robocopy is giving error with compiled script
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: robocopy is giving error with compiled script
Fortunately both the location or directory are available.
Re: robocopy is giving error with compiled script
Hello
Has anyone found the solution?
I am still stuck on same issue, I tested this in PS 2.0/4.0/5.0, everywhere it is same issue.
Any other approach to resolve this issue?
Has anyone found the solution?
I am still stuck on same issue, I tested this in PS 2.0/4.0/5.0, everywhere it is same issue.
Any other approach to resolve this issue?
Re: robocopy is giving error with compiled script
Hi jvierra
Following code suggested by and it seems to be perfect, there is nothing wrong in the variable but I am still getting error when I run it as compiled exe, however file is getting copy.
Secondly I direct run as script instead of compiled exe, I don't get any error.
$logLocal = "c:\users\$Env:USERNAME\AppData\Local\MyLogs"
$centralizedLocation = 'c:\appLogs'
$filename = "$Env:USERNAME_AdminActivity_$logDate.txt"
# check target file
$targetFilePath = join-Path $logLocal $filename
if (Test-Path $targetFilePath) {
robocopy $logLocal $centralizedLocation $filename
} else {
Write-Host 'File not found'
}
Following code suggested by and it seems to be perfect, there is nothing wrong in the variable but I am still getting error when I run it as compiled exe, however file is getting copy.
Secondly I direct run as script instead of compiled exe, I don't get any error.
$logLocal = "c:\users\$Env:USERNAME\AppData\Local\MyLogs"
$centralizedLocation = 'c:\appLogs'
$filename = "$Env:USERNAME_AdminActivity_$logDate.txt"
# check target file
$targetFilePath = join-Path $logLocal $filename
if (Test-Path $targetFilePath) {
robocopy $logLocal $centralizedLocation $filename
} else {
Write-Host 'File not found'
}
Re: robocopy is giving error with compiled script
You code makes no sense. It is testing if a file exists in the target locations before it is copied.
I suspect you are doing something that is not seeable in what you have posted.
I suspect you are doing something that is not seeable in what you have posted.
Re: robocopy is giving error with compiled script
Hi
My original code which I posted in my first post was, I was getting same error here as well
$logLocal = "c:\users\$Env:USERNAME\AppData\Local\MyLogs\"
$centralizedLocation = "c:\appLogs\"
$copyLog=$logLocal +$Env:USERNAME+"_"+ "AdminActivity" +"_"+$logDate +".txt"
$filename = Split-Path $copyLog -leaf
robocopy $logLocal $centralizedLocation $filename
Then Davinl suggested code in a different manner, which I posted in my last email.
Anyway I posted my initial code for your reference, if you have some idea pls let me know.
My original code which I posted in my first post was, I was getting same error here as well
$logLocal = "c:\users\$Env:USERNAME\AppData\Local\MyLogs\"
$centralizedLocation = "c:\appLogs\"
$copyLog=$logLocal +$Env:USERNAME+"_"+ "AdminActivity" +"_"+$logDate +".txt"
$filename = Split-Path $copyLog -leaf
robocopy $logLocal $centralizedLocation $filename
Then Davinl suggested code in a different manner, which I posted in my last email.
Anyway I posted my initial code for your reference, if you have some idea pls let me know.
Re: robocopy is giving error with compiled script
I can run that code with no issues.
This:
As an EXE has no issues. RoboCopy is silly for copying one file but it works with no issues. You have some other problem that is not shown in what you have posted.
Write you code the way I have above and just insert the correct file name and test.
This:
- $filename = 'test.txt'
- $logLocal = "$env:USERPROFILE\AppData\Local\MyLogs"
- $centralizedLocation = 'c:\appLogs'
- robocopy $logLocal $centralizedLocation $filename
- Write-Host done
- Read-Host 'Enter to exit'
Write you code the way I have above and just insert the correct file name and test.