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?

  • 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 '16 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 '16 at 20:21

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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.