Home Forums Programming Powershell Vbscript SQL and fOREFRONT TMG Help !! RE: Vbscript SQL and fOREFRONT TMG Help !!

  • Seriously...get this person some PowerShell 😎

    Add-Type -AssemblyName “Microsoft.SqlServer.Smo”

    ##################################################################

    # initialize variables

    $instanceName = "myserver\myinstancename"

    $databaseName = "mydatabase"

    $login = "testlogin" # leave blank to use Windows Authentication

    $password = "password"

    $sql = "delete FROM WebProxyLog WHERE logtime <= getdate()-60"

    $statementTimeout = 600 # in seconds; set to 0 to allow statement to execute indefinitely

    ##################################################################

    # do work (nothing below here needs to change)

    $instance = New-Object('Microsoft.SqlServer.Management.Smo.Server') $instanceName

    if($login)

    {

    $instance.ConnectionContext.LoginSecure = False

    $instance.ConnectionContext.Login = $login

    $instance.ConnectionContext.Password = $password

    }

    $instance.ConnectionContext.StatementTimeout = $statementTimeout

    $database = $instance.Databases.Item($databaseName)

    $database.ExecuteNonQuery($sql)

    EDIT: updated to support statement timeout

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato