I am trying to create a backup using the below script but this script creates the backup into default backup folder, how to specify a user defined folder e.g c:\backup
$dbToBackup = "inventory"
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended") |
Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo")
| Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum") | Out-
Null
#create a new server object
$server = New-Object ("Microsoft.SqlServer.Management.Smo.Server") "(local)"
$backupDirectory = $server.Settings.BackupDirectory
#display default backup directory
"Default Backup Directory: " + $backupDirectory
read-host "stop"
#i put stop here to see the default directory that is C:\Program Files\Microsoft SQL
Server\MSSQL10_50.MSSQLSERVER\MSSQL\Backup
$db = $server.Databases[$dbToBackup]
$dbName = $db.Name
I have modified the script but still not getting the new location appeard in screen
Add-Type -AssemblyName "Microsoft.SqlServer.Smo, Version=10.0.0.0, Culture=neutral,
PublicKeyToken=89845dcd8080cc91"
$server = New-Object Microsoft.SqlServer.Management.Smo.Server($env:ComputerName)
$server.Properties["BackupDirectory"].Value = "K:\Backup"
$server.Alter()
$backupDirectory = $server.Settings.BackupDirectory
#display default backup directory
"Default Backup Directory: " + $backupDirectory
read-host "Stop"
$server.Settings.BackupDirectory="c:\yourfolder"??