robocopy is giving error with compiled script

Ask your PowerShell-related questions, including questions on cmdlet development!
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.
This topic is 6 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
ashishk
Posts: 19
Last visit: Mon Apr 10, 2017 12:08 am

robocopy is giving error with compiled script

Post 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
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: robocopy is giving error with compiled script

Post by DevinL »

When you package this into an exe, which engine are you using and which version of PowerShell are you targeting?
DevinL
SAPIEN Technologies, Inc.
User avatar
ashishk
Posts: 19
Last visit: Mon Apr 10, 2017 12:08 am

Re: robocopy is giving error with compiled script

Post by ashishk »

HI
I am giving "Sapien PowerShell v2 Host(CommandLine)" as Engine and I am targeting PowerShell 2.0.

Please advise
Avian
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: robocopy is giving error with compiled script

Post 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.
DevinL
SAPIEN Technologies, Inc.
User avatar
ashishk
Posts: 19
Last visit: Mon Apr 10, 2017 12:08 am

Re: robocopy is giving error with compiled script

Post 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.
User avatar
ashishk
Posts: 19
Last visit: Mon Apr 10, 2017 12:08 am

Re: robocopy is giving error with compiled script

Post by ashishk »

Can any one please help me out on above mentioned issue?
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: robocopy is giving error with compiled script

Post by DevinL »

Sorry, I'm looking into this today and I will get back to you as soon as possible.
DevinL
SAPIEN Technologies, Inc.
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: robocopy is giving error with compiled script

Post 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 15197 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.
Attachments
Robocopy_Test.ps1.zip
(1.35 KiB) Downloaded 146 times
DevinL
SAPIEN Technologies, Inc.
User avatar
ashishk
Posts: 19
Last visit: Mon Apr 10, 2017 12:08 am

Re: robocopy is giving error with compiled script

Post 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.
Attachments
error1.jpg
error1.jpg (264.07 KiB) Viewed 15173 times
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: robocopy is giving error with compiled script

Post 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 15090 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.
DevinL
SAPIEN Technologies, Inc.
This topic is 6 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked