TheDizzle
TheDizzle

Reputation: 1574

How to bypass Backup-SqlDatabase prompt for password?

I'm writing a powershell script to run some sql backups to a network share. Is there a way to get around the password prompt?

Backup-SqlDatabase -ServerInstance $SQLServer -Database $DatabaseName -BackupFile "\\network-share\MainDB.bak" -Credential (Get-Credential "sa")

Currently this prompts me for a password. I'd like for these to run automatically without any user intervention.

Upvotes: 2

Views: 1803

Answers (1)

4c74356b41
4c74356b41

Reputation: 72171

just create a credential object and pass it in as you normally would:

$cred = [pscredential]::new('administrator',(ConvertTo-SecureString -String '!Q2w3e4r' -AsPlainText -Force))
Backup-SqlDatabase -ServerInstance $SQLServer -Database $DatabaseName -BackupFile "\\network-share\MainDB.bak" -Credential $cred

Upvotes: 6

Related Questions