'Initial source for this script: http://www.technowledgebase.com/2007/06/12/vbscript-how-to-create-an-ado-connection-and-run-a-query/ Dim objCN Set objCN=CreateObject("ADODB.Connection") ' If you want to use a username & password to connect to SQL, then add in this after Persist Security Info=False: User ID=;Password=; and take out the Integrated Security part. objCN.Open "Provider=SQLOLEDB.1;Persist Security Info=False;Integrated Security=SSPI;Initial Catalog=SMS_XYZ;Data Source=SiteServer" 'objCN.Open connectionstring if(err.number<>0) then 'connectionfailed! else 'runthequery! end if Dim strSQL ' If you created the v_RequiredUpdates view, then use this query: strSQL="SELECT DISTINCT dbo.v_RequiredUpdates.SourceUrl FROM dbo.v_RequiredUpdates" ' If you did not create the v_RequiredUpdates view, then use this query: 'strSQL="SELECT DISTINCT TOP (100) PERCENT dbo.CI_ContentFiles.SourceURL FROM dbo.v_Update_ComplianceStatusAll INNER JOIN dbo.v_UpdateContents ON dbo.v_Update_ComplianceStatusAll.CI_ID = dbo.v_UpdateContents.CI_ID INNER JOIN dbo.v_UpdateInfo ON dbo.v_UpdateContents.CI_ID = dbo.v_UpdateInfo.CI_ID INNER JOIN dbo.CI_ContentFiles ON dbo.v_UpdateContents.Content_ID = dbo.CI_ContentFiles.Content_ID WHERE (dbo.v_Update_ComplianceStatusAll.Status = 2) AND (dbo.v_UpdateContents.ContentLocales = 'English' OR dbo.v_UpdateContents.ContentLocales = ' ') AND (dbo.v_UpdateInfo.IsExpired = 'False') AND (dbo.v_UpdateContents.ContentProvisioned = 0)" Dim objRS set objRS=objCN.execute(strSQL) if err.number<>0 then 'something bad happened objCN.Close Set objRS=nothing Set objCN=nothing else 'the query ran perfectly end if if objRS.eof then 'no records returned else 'we got some records! 'do something with SourceURL Dim objFileSystem, objOutputFile Dim strOutputFile ' generate source URL file strOutputFile = "SourceURLs.txt" Set objFileSystem = CreateObject("Scripting.fileSystemObject") Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile, TRUE) Dim i Dim fs i=0 DO WHILe NOT objRS.eof strURL=objRS("SourceURL") objOutputFile.writeline strURL i=i+1 objRS.MoveNext Loop objOutputFile.Close Set objFileSystem = Nothing End if MsgBox i & " source urls found and written to " & strOutputFile,0,"Query Complete!" objCN.Close Set objRS=nothing Set objCN=nothing wscript.quit