Nuno
Nuno

Reputation: 126

Backup-SqlDatabase PsDrive Filesystem

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.

Upvotes: 1

Views: 740

Answers (1)

Vasiliy Plotnikov
Vasiliy Plotnikov

Reputation: 23

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

Check Scope section in the doc

Upvotes: 0

Related Questions