Problem with Getfiles path incorrect when using powershell

Advertisement

kwslavens
Joined:
Posts:
3
Location:
US MO

Problem with Getfiles path incorrect when using powershell

I'm working on a simple download of specific files and I've run into this issue.

This works.
$session.GetFiles("/Extract/SCTM.xlsx","e:\File-Hold\").Check()


This Does not.
$SourceFile = "/Extract/SCTM.xlsx"
$TargetFolder = "e:\File-Hold\"
$session.GetFiles($SourceFile,$TargetFolder).Check()

The problem in the log seems to be that the path doesn't resolve as expected.

> 2013-06-12 11:37:10.120 Script: get -nopermissions -preservetime -transfer="binary" -- "/Extract/SCTM.xlsx e:\File-Hold\" ""

It seems to be adding the 2 paths together as a source file and setting the targetfolder to be blank.

I've tried a lot of different ideas to get the variable paths to work but always comes back incorrect in the logs giving error
Can't get attributes of file '/Extract/SCTM.xlsx e:\File-Hold\'.


Any idea's why this is happening. I'm running the code on a 2012 server running powershell 3.0.

Reply with quote

Advertisement

kwslavens
Joined:
Posts:
3
Location:
US MO

Another UPDATE:

This seems to only happen in the situation where the variables are being passed in as parameters to a function.

$SourceFile = "/Extract/SCTM.xlsx"
$TargetFolder = "e:\File-Hold\"
$session.GetFiles($SourceFile,$TargetFolder).Check()

Works fine...


function DOWNLOAD($SourceFile,$TargetFolder)
{
$session.GetFiles($SourceFile,$TargetFolder).Check()
}

DOWNLOAD("/Extract/SCTM.xlsx","e:\File-Hold\")


This on the other hand results in the problem I posted. Where the path for source and destination are combined.

Reply with quote

Caine
Joined:
Posts:
1
Location:
PAC NW, USA

You need to add invoke to the script line:

$session.GetFiles.invoke($SourceFile,$TargetFolder).Check()

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

Re: Problem with Getfiles path incorrect when using powershell

This definitely looks like a problem with your PowerShell syntax. I'm not that familiar with PowerShell to help you and it seems out of scope of this forum anyway. Consider asking on https://stackoverflow.com/. Please post a link here, if you do.

Reply with quote

Advertisement

You can post new topics in this forum