September 14, 2018 at 8:25 am
I am looking for powershell script to script out alters and operators, can someone help
September 14, 2018 at 8:45 am
goher2000 - Friday, September 14, 2018 8:25 AMI am looking for powershell script to script out alters and operators, can someone help
Alters to what?
If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.
September 14, 2018 at 8:54 am
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null
$a = New-Object Microsoft.SqlServer.Management.Smo.ScriptingOptions
$DateTime = (Get-Date).ToString("yyyyMMdd-HHmmss")
$instanceName = "$(ESCAPE_SQUOTE(SRVR))";
$instanceName = $instanceName.Replace("\","$")
$directory_location = "H:\SQL_Backups" + $instanceName + "\Objects"
new-item $directory_location -itemtype directory
$a.filename = $directory_location + "\_" + $DateTime + "_Operators.sql"
$a.AppendToFile = $True
$a.ToFileOnly = $true
$a.ScriptBatchTerminator = $true
$srv = New-Object "Microsoft.SqlServer.Management.Smo.Server" $(ESCAPE_SQUOTE(SRVR))
$srv.JobServer.Operators | foreach {$_.Script($a)}
This is for operators. I do not script out alerts, they are the same set on every servers.
Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
September 14, 2018 at 12:20 pm
goher2000 - Friday, September 14, 2018 8:25 AMI am looking for powershell script to script out alters and operators, can someone help
DBATools (https://dbatools.io/) makes this really simple and will generate valid sp_add* scripts for you.
$server = 'ServerName' #specify your target server
$filename = 'C:\outputfolder\{0}_export.sql' -f ($server) #change your folder and name your output file
get-dbaagentalert -sqlserver $server | export-dbascript -path $filename -append
get-dbaagentoperator -sqlserver $server | export-dbascript -path $filename -append
It's also a great toolset in general for SQL Server operations and administration.
September 14, 2018 at 12:58 pm
SQLPirate - Friday, September 14, 2018 12:20 PMgoher2000 - Friday, September 14, 2018 8:25 AMI am looking for powershell script to script out alters and operators, can someone helpDBATools (https://dbatools.io/) makes this really simple and will generate valid sp_add* scripts for you.
$server = 'ServerName' #specify your target server
$filename = 'C:\outputfolder\{0}_export.sql' -f ($server) #change your folder and name your output fileget-dbaagentalert -sqlserver $server | export-dbascript -path $filename -append
get-dbaagentoperator -sqlserver $server | export-dbascript -path $filename -appendIt's also a great toolset in general for SQL Server operations and administration.
Which is actually what I am in the process of switching to!
Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
September 14, 2018 at 2:29 pm
Michael L John - Friday, September 14, 2018 12:58 PMWhich is actually what I am in the process of switching to!
I can't say enough good things about it. It's easily the most handy toolset I've adopted for tasks of this nature.
September 17, 2018 at 9:09 am
Thanks Guys
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply