1

I'm trying to backup a SQL database to a remote location, with the Backup-SqlDatabase cmdlet, to a PSDrive (filesystem) with no success.

I am creating a PSDrive for example \\server\sharedFolder with a name TARGET.

New-PSDrive –Name TARGET -PSProvider FileSystem -Root \\server\sharedfolder -Credential (Get-Credentials)

but when I run the backup like:

Backup-SqlDatabase -ServerInstance $server -Database $dbName -BackupFile "TARGET:bckfile.bak" -Credential $sqlCredentials

I get a completely different location and error:

Backup-SqlDatabase : System.Data.SqlClient.SqlError: Cannot open backup device 'E:\SQL_BCK\TARGET\TARGET:bckfile.bak'. Operating system error 3 (The system cannot find the path specified.).

But if I run the backup like:

Backup-SqlDatabase -ServerInstance $server -Database $dbName -BackupFile "\\server\sharedfolder\bckfile.bak" -Credential $sqlCredentials

I have no problems.

The issue is, I need to access the shared folder with different credentials, so the PSDrive was the perfect solution, because during configration I ask the user for credentials.

3
  • How do you create the psdrive TARGET? If you create it on your local workstation, it isn't visible on the server that is actually writing the data. Commented Feb 1, 2017 at 17:30
  • New-PSDrive –Name TARGET -PSProvider FileSystem -Root \\server\sharedfolder -Credential (Get-Credentials)... the target is correct... but doesn't work when used in the backup-sqldatabase Commented Feb 1, 2017 at 17:34
  • Try New-PSDrive ... -Persist. Commented Feb 2, 2017 at 11:14

1 Answer 1

0

Try to add -Scope "Script" into New-PSDrive

Check Scope section in the doc

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.