robocopy is giving error with compiled script

Ask your Windows 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.
User avatar
ashishk
Posts: 19
Joined: Mon Feb 13, 2017 1:09 pm

robocopy is giving error with compiled script

Post by ashishk » Mon Mar 27, 2017 2:53 pm

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

User avatar
DevinL
Site Admin
Posts: 1098
Joined: Mon Aug 17, 2015 2:25 pm

Re: robocopy is giving error with compiled script

Post by DevinL » Tue Mar 28, 2017 8:41 am

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
Joined: Mon Feb 13, 2017 1:09 pm

Re: robocopy is giving error with compiled script

Post by ashishk » Tue Mar 28, 2017 9:20 am

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

Please advise
Avian

User avatar
DevinL
Site Admin
Posts: 1098
Joined: Mon Aug 17, 2015 2:25 pm

Re: robocopy is giving error with compiled script

Post by DevinL » Tue Mar 28, 2017 9:23 am

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
Joined: Mon Feb 13, 2017 1:09 pm

Re: robocopy is giving error with compiled script

Post by ashishk » Tue Mar 28, 2017 10:50 am

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
Joined: Mon Feb 13, 2017 1:09 pm

Re: robocopy is giving error with compiled script

Post by ashishk » Thu Mar 30, 2017 6:02 am

Can any one please help me out on above mentioned issue?

User avatar
DevinL
Site Admin
Posts: 1098
Joined: Mon Aug 17, 2015 2:25 pm

Re: robocopy is giving error with compiled script

Post by DevinL » Thu Mar 30, 2017 3:32 pm

Sorry, I'm looking into this today and I will get back to you as soon as possible.
DevinL
SAPIEN Technologies, Inc.

User avatar
DevinL
Site Admin
Posts: 1098
Joined: Mon Aug 17, 2015 2:25 pm

Re: robocopy is giving error with compiled script

Post by DevinL » Thu Mar 30, 2017 4:10 pm

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):

Code: Select all

# Original script lacked the source for $LogDate, so I use this in its place
$LogDate = Get-Date -Format "M.d.yyy_HH.mm.ss"

# Replaced C:\Users\$env:USERNAME with $env:USERPROFILE
$LogLocal = "$env:USERPROFILE\AppData\Local\MyLogs\"
$CentralizedLocation = "C:\AppLogs\"
$CopyLog = $LogLocal + $Env:USERNAME + "_AdminActivity_" + $LogDate + ".txt"
$Filename = Split-Path $CopyLog -leaf

# Verified the file existed, if not, create it so robocopy won't throw an error
if (-not (Test-Path $CopyLog)) {
New-Item -Path $CopyLog -ItemType File
}

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 12797 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 50 times
DevinL
SAPIEN Technologies, Inc.

User avatar
ashishk
Posts: 19
Joined: Mon Feb 13, 2017 1:09 pm

Re: robocopy is giving error with compiled script

Post by ashishk » Thu Mar 30, 2017 10:02 pm

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 12773 times

User avatar
DevinL
Site Admin
Posts: 1098
Joined: Mon Aug 17, 2015 2:25 pm

Re: robocopy is giving error with compiled script

Post by DevinL » Fri Mar 31, 2017 9:13 am

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 12690 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.

Locked