Page 1 of 3

robocopy is giving error with compiled script

Posted: Mon Mar 27, 2017 2:53 pm
by ashishk
Product, version and build:
(*** Please do not write "latest" as a version, specify a version number ***)
32 or 64 bit version of product:64
Operating system:WIN7
32 or 64 bit OS:64 bit


I am using following command to copy one file from one location to another location using powershell compiled script I am getting following error. However when I run this directly in powershell script I am not getting error

 .At line:3 char:17

robocopy $loglocal $logcentral $filename

I am getting error

Program 'Robocopy.exe' failed to run: The method or operation is not implemented at line 3 char 7.

However file is copying.

Please let me know what wrong I am doing here

Re: robocopy is giving error with compiled script

Posted: Tue Mar 28, 2017 8:41 am
by DevinL
When you package this into an exe, which engine are you using and which version of PowerShell are you targeting?

Re: robocopy is giving error with compiled script

Posted: Tue Mar 28, 2017 9:20 am
by ashishk
HI
I am giving "Sapien PowerShell v2 Host(CommandLine)" as Engine and I am targeting PowerShell 2.0.

Please advise
Avian

Re: robocopy is giving error with compiled script

Posted: Tue Mar 28, 2017 9:23 am
by DevinL
In that case, can you provide the script you're working with? I'm still unable to reproduce this on my end and knowing more about the structure of your script could help point us in the right direction.

If need be, you can upload it to https://sapien.com/support/upload and the code will remain private.

Re: robocopy is giving error with compiled script

Posted: Tue Mar 28, 2017 10:50 am
by ashishk
Hi

Here is the script

$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

Let me know if you need more information.

Re: robocopy is giving error with compiled script

Posted: Thu Mar 30, 2017 6:02 am
by ashishk
Can any one please help me out on above mentioned issue?

Re: robocopy is giving error with compiled script

Posted: Thu Mar 30, 2017 3:32 pm
by DevinL
Sorry, I'm looking into this today and I will get back to you as soon as possible.

Re: robocopy is giving error with compiled script

Posted: Thu Mar 30, 2017 4:10 pm
by DevinL
Unfortunately, I'm unable to reproduce this on my end at the moment, here is what I did in my attempt to reproduce it:

First I copied your script over and cleaned it up a bit to work in my current environment and this was the end result (I've also attached the script and psbuild to the bottom of this post just in case):
  1. # Original script lacked the source for $LogDate, so I use this in its place
  2. $LogDate = Get-Date -Format "M.d.yyy_HH.mm.ss"
  3.  
  4. # Replaced C:\Users\$env:USERNAME with $env:USERPROFILE
  5. $LogLocal = "$env:USERPROFILE\AppData\Local\MyLogs\"
  6. $CentralizedLocation = "C:\AppLogs\"
  7. $CopyLog = $LogLocal + $Env:USERNAME + "_AdminActivity_" + $LogDate + ".txt"
  8. $Filename = Split-Path $CopyLog -leaf
  9.  
  10. # Verified the file existed, if not, create it so robocopy won't throw an error
  11. if (-not (Test-Path $CopyLog)) {
  12.     New-Item -Path $CopyLog -ItemType File
  13. }
  14.  
  15. robocopy $LogLocal $CentralizedLocation $Filename
I added comments to the major changes I made so you can see what I did much easier.

I packaged this script into an exe using the SAPIEN PowerShell V2 Host (Command Line) engine, and targetted the 64-bit platform, all other packager settings remained the defaults.

Here is a screenshot of the results when I ran the executable on my machine:
Robocopy_Test.png
Robocopy_Test.png (41.12 KiB) Viewed 15194 times
Were there any steps that I may have taken differently than how it is run in your environment? If so, please let me know and I'll do my best to reproduce. In the meantime, I'll see if I can't find a workaround to get your script working.

Re: robocopy is giving error with compiled script

Posted: Thu Mar 30, 2017 10:02 pm
by ashishk
Hello Devinl

I downloaded your code and compiled the exe but getting same error. Please see the attached error.

Is it because I am using trial version of Primal Script 2017?

My Current environment is Windows 7 64 bit and OS is also 64 bit.

Please advise.

Re: robocopy is giving error with compiled script

Posted: Fri Mar 31, 2017 9:13 am
by DevinL
The fact that you're using a trial version shouldn't have any effect, I just fired up a Windows 7 64-bit machine with a trial installation of PrimalScript and was able to build and execute the script as expected:
Robocopy_WIN764_Trial.png
Robocopy_WIN764_Trial.png (70.75 KiB) Viewed 15087 times
It seems to be executing correctly, but then attempting to execute itself again only to error. You did point out that the file is copying, so I'm thinking this is something to do with the specific environment on that machine. I'll speak with the team and see what ideas they may have and get back to you.