Script Operators using SQLDMO

Below is a VBScript code sample illustrating how to use SQLDMO to generate a SQL script of all of the operators on a SQL Server instance to assist in migrating from one instance to another:

Const SQLDMOScript_Drops = 1
Const SQLDMOScript_Default = 4

Const SCRIPT_FILE = “c:\operators.txt”

Const ForWriting = 2

Dim oSQLServer
Dim oFSOWrite
Dim oFSO
Dim txt
Dim op

Set oSQLServer = CreateObject(“SQLDMO.SQLServer”)
Set oFSO = CreateObject(“Scripting.FileSystemObject”)

Set oFSOWrite = oFSO.OpenTextFile(SCRIPT_FILE, ForWriting, True)

oSQLServer.LoginSecure = True
oSQLServer.Connect “(local)”

For each op in oSQLServer.JobServer.Operators
txt = op.Script(SQLDMOScript_Drops + SQLDMOScript_Default)
oFSOWrite.Write txt


Set oFSOWrite = Nothing
Set oSQLServer = Nothing