VBS Script To Export SMS WQL System Resource Queries To Microsoft Word

 

This Vbs script will take an SMS site server name and site code from an input box and then enumerate all of the System queries on that server and read their corresponding WQL Queries. It will then write them to a Microsoft Word document that you can save for future reference.

 

VBS Script:

 

strComputer = InputBox ("Enter Site Server Name")

strSiteCode = InputBox("Enter Site Code")

 

Set objWord = CreateObject("Word.Application")

objWord.Visible = True

 

Const wdAlignParagraphCenter = 1

Const wdAlignParagraphLeft = 0 

 

Const wdColorGreen = 32768

Const wdColorBlue = 16711680

Const wdColorBlack = 0

Const wdColorGray = 15132390

 

Set objDoc = objWord.Documents.Add()

Set objSelection = objWord.Selection

 

objSelection.Font.Bold = True

objSelection.Font.Color = wdColorGreen

objSelection.ParagraphFormat.Alignment = wdAlignParagraphCenter

objSelection.TypeText "SMS WQL System Resource Queries For " & UCase(strComputer)

objSelection.Font.Bold = False

objSelection.TypeParagraph()

objSelection.TypeText "Report Created: " & Date

objSelection.TypeParagraph()

objSelection.TypeParagraph()

objSelection.ParagraphFormat.Alignment = wdAlignParagraphLeft

 

Set objWMIService = GetObject("winmgmts://" & strComputer & "\root\sms\site_" & strSiteCode)

Set colItems = objWMIService.ExecQuery("Select * from SMS_Query Where TargetClassName = 'SMS_R_System'")

For Each objItem in colItems

 

objSelection.ParagraphFormat.Alignment = wdAlignParagraphCenter

objSelection.Font.Color = wdColorBlue

objSelection.Font.Bold = True

objSelection.ParagraphFormat.Shading.BackgroundPatternColor = wdColorGray

objSelection.TypeText objItem.Name

objSelection.TypeParagraph()

objSelection.TypeParagraph()

 

objSelection.ParagraphFormat.Alignment = wdAlignParagraphLeft

objSelection.Font.Color = wdColorBlack

objSelection.Font.Bold = False

objSelection.TypeText objItem.Expression

objSelection.TypeParagraph()

objSelection.TypeParagraph()

Next

 

objSelection.ParagraphFormat.Alignment = wdAlignParagraphCenter

objSelection.Font.Color = wdColorGreen

objSelection.TypeText "Created by Don Hite For myITforum.Com"

objSelection.TypeParagraph()

 

VBS Script To Export SMS Queries To Microsoft Word

http://myitforum.com/cs2/blogs/dhite/archive/2008/02/24/vbs-script-to-export-sms-queries-to-microsoft-word.aspx

 

 

 

Published Sunday, March 30, 2008 7:43 AM by dhite
Filed under:

Comments

No Comments