2

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.

1 Answer 1

6

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
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.