0

I have a backup script that is supposed to target a specific local folder and backup the folder to a remote shared folder on another server.

When I run my script, Powershell prompts me with the following error:

One of the file paths specified for backup is that of a remote shared folder. Backup of a remote shared folder is not allowed.

The following code is the cause for the underlying issue:

$current_day = ("\\backupsrv01\Homes\" + $day)

The variable $day is just the current day.

$date = Get-Date
$day = $date.DayOfWeek

How can I successfully target a remote share using Powershell?

2
  • 1
    If I'm reading the error message correctly, it's saying that you're trying to backup a remote shared folder, not backup to a remote shared folder.
    – GregL
    May 18, 2016 at 16:48
  • 1
    I feel that your question should be asked at stackoverflow.com rather than here. However follow their How to create a Minimal, Complete, and Verifiable example requirements: please edit your quetion and show backup code snippet with source(s) and target. I agree with @GregL.
    – JosefZ
    May 18, 2016 at 20:21

1 Answer 1

0

Hard to get at what you're trying to do here (What backup software? What else is in your script?) But i'll give it a shot...

You could try invoking the Powershell onto the remote server

An example of how this can work is

function MyBackup {
    # Whatever you backup is doing 
}

$Credz = Get-Credential
$MySession = New-PSSession $TargetServer -Credential $Credz
Invoke-Command -Session $MySession -ScriptBlock ${function:MyBackup}

That way the Powershell you're running is running on the targethost as opposed to your machine running it.

If you need to pass parameters into a function you're Invoking that can be done like so

$Item = "Cap"
$Colour = "Red"

function RemoteParameters {
    param($Item, $Colour)
    Write-Host "The $Item is $Colour"
}

Invoke-Command -Session $MySession -ScriptBlock ${function:RemoteParameters} -ArguementList $Item,$Colour

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .