Page 3 of 3

Re: robocopy is giving error with compiled script

Posted: Sun Apr 02, 2017 9:29 pm
by jvierra
You are trying to copy to or from a location that is not available. "CategoryInfo : ResourceUnavailable: "

Re: robocopy is giving error with compiled script

Posted: Mon Apr 03, 2017 3:43 am
by ashishk
Fortunately both the location or directory are available.

Re: robocopy is giving error with compiled script

Posted: Wed Apr 05, 2017 7:36 pm
by ashishk
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?

Re: robocopy is giving error with compiled script

Posted: Wed Apr 05, 2017 7:38 pm
by jvierra
Something in your variables is wrong. We cannot see your system. You will need to carefully inspect your variables and test them independently.

Re: robocopy is giving error with compiled script

Posted: Thu Apr 06, 2017 10:54 pm
by ashishk
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'
}

Re: robocopy is giving error with compiled script

Posted: Thu Apr 06, 2017 11:01 pm
by jvierra
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.

Re: robocopy is giving error with compiled script

Posted: Fri Apr 07, 2017 10:29 am
by ashishk
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.

Re: robocopy is giving error with compiled script

Posted: Fri Apr 07, 2017 10:50 am
by jvierra
I can run that code with no issues.

This:

Code: Select all

$filename = 'test.txt'
$logLocal = "$env:USERPROFILE\AppData\Local\MyLogs"
$centralizedLocation = 'c:\appLogs'
robocopy $logLocal $centralizedLocation $filename
Write-Host done
Read-Host 'Enter to exit'
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.