Set Objects of a SMO variable

  • I believe you are very close here you just need to save the changes (so to speak).

    I think this will get it for you.

    [System.Reflection.Assembly]::LoadWithPartialName(’Microsoft.SqlServer.SMO’) | Out-Null

    $smo = New-Object (’Microsoft.SqlServer.Management.Smo.Server’) "Server\Instance"

    $jobstodisable= get-content C:\jobstodisablefile.txt

    for($i=0; $i -lt $jobstodisable.count; $i++)

    {

    $job= $smo.Jobserver.jobs | where-object {$_.name -eq $jobstodisable[$i]}

    $job.isenabled = 0

    $job.Alter()

    }

  • I really feel foolish that I never noticed that I was not committing the changes made to the object.

    Your point worked for me. thanks Mike.

    SQLSErverCentral is really helpfull.

Viewing 2 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply