Thursday, July 31, 2008

VBS Script To Export SMS Queries To Microsoft Word

VBS Script To Export SMS WQL User 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 User 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 = TrueConst wdAlignParagraphCenter = 1Const wdAlignParagraphLeft = 0 Const wdColorGreen = 32768Const wdColorBlue = 16711680 Const wdColorBlack = 0Const wdColorGray = 15132390Set objDoc = objWord.Documents.Add()Set objSelection = objWord.SelectionobjSelection.Font.Bold = TrueobjSelection.Font.Color = wdColorGreenobjSelection.ParagraphFormat.Alignment = wdAlignParagraphCenter objSelection.TypeText "SMS WQL User Resource Queries For " & UCase(strComputer)objSelection.Font.Bold = FalseobjSelection.TypeParagraph()objSelection.TypeText "Report Created: " & DateobjSelection.TypeParagraph()objSelection.TypeParagraph()objSelection.ParagraphFormat.Alignment = wdAlignParagraphLeftSet objWMIService = GetObject("winmgmts://" & strComputer & "\root\sms\site_" & strSiteCode)Set colItems = objWMIService.ExecQuery("Select * from SMS_Query Where TargetClassName = 'SMS_R_User'")For Each objItem in colItemsobjSelection.ParagraphFormat.Alignment = wdAlignParagraphCenter objSelection.Font.Color = wdColorBlueobjSelection.Font.Bold = TrueobjSelection.ParagraphFormat.Shading.BackgroundPatternColor = wdColorGrayobjSelection.TypeText objItem.Name objSelection.TypeParagraph()objSelection.TypeParagraph()objSelection.ParagraphFormat.Alignment = wdAlignParagraphLeftobjSelection.Font.Color = wdColorBlackobjSelection.Font.Bold = FalseobjSelection.TypeText objItem.ExpressionobjSelection.TypeParagraph()objSelection.TypeParagraph()NextobjSelection.ParagraphFormat.Alignment = wdAlignParagraphCenter objSelection.Font.Color = wdColorGreenobjSelection.TypeText "Created by Don Hite For myITforum.Com"objSelection.TypeParagraph()VBS Script To Export SMS Queries To Microsoft Word

No comments: