I am writing a powershell script that makes a backup of all databases in a SQL Server.
If during backup an error occurs I'd like to suppress the standard error message because I am handling the errors myself. I succeed in trapping the exception but the standard error message still appears.
How can I suppress the standard error message in the powershell script.
this is the code to do the backup
$svr = New-Object ('Microsoft.SqlServer.Management.Smo.Server') $sqlservername
$dbBackup = New-Object ("Microsoft.SqlServer.Management.Smo.Backup")
$dbBackup.Database = $dbName
$dbBackup.Devices.AddDevice($FilePath, "File")
$dbBackup.Action = "Database"
$dbBackup.SqlBackup($svr)
$dbBackup.Wait()
and I trap the error with this
Trap [Exception]
{
#error handling
}
thanks for your help
Did you try what this author suggests? http://arcware.net/how-to-suppress-powershell-errors/
Set the ErrorAction
parameter to SilentlyContinue
?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.