sComputer = "SWYNKSRV01" '-- name of the computer where SQL Server is installed sSQLServer = "SWYNKSRV01" '-- name of the SQL server instance containing the database where the target table is located sDb = "Northwind" '-- name of the database containing the target table sTable = "Orders" '-- name of the target table iFillFactor = 50 '-- Fill Factor value for table index rebuilding Set oInstance = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _ sComputer & "/root/MicrosoftSQLServer:MSSQL_Table.SQLServerName=" & _ Chr(34) & sSQLServer & Chr(34) & ",DatabaseName=" & Chr(34) & _ sDb & Chr(34) & ",Name=" & Chr(34) & sTable & Chr(34)) Set oOutParam = oInstance.RebuildIndexes(0,iFillFactor) If oOutParam.ReturnValue = 0 Then WScript.Echo "Indexes on the table " & sTable & " have been rebuilt successfully" Else WScript.Echo "Rebuilding indexes on the table " & sTable & " failed with the error " & oOutParam.Description End If