April 10, 2012 at 12:39 pm
I'm using this bit of code in a powershell script to see if a job is enabled:
$srv = New-Object "Microsoft.SqlServer.Management.Smo.Server" $sqlserver;
foreach ($job in $srv.Jobserver.Jobs)
$jobEnabled = $job.IsEnabled;
However that value always comes back as "true". I've disabled the job and I've disabled the schedule for that job but still comes back as true. All the other properties seem to be correct (name, LastRunDate, etc.) Am I doing something wrong or does anyone have any suggestions?
Thanks!
Derek
April 10, 2012 at 1:41 pm
Did you import the assembly? This works fine for me:
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null
$srv = New-Object Microsoft.SqlServer.Management.SMO.Server("N3011SIM")
foreach ($job in $srv.Jobserver.Jobs)
{
$job.Name + " = " + $job.IsEnabled;
}
If this does not solve it for you...which version of SMO is installed? Look for Microsoft.SqlServer.Smo in C:\WINDOWS\assembly
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
April 10, 2012 at 2:18 pm
Thank you for the reply. I went back and look to see if there was difference in our code... what I did discover is later in my code. This is not a great idea:
if($jobEnabled = "true")
{
🙂
Thank you for the help!
April 10, 2012 at 2:58 pm
Derek Gemmen (4/10/2012)
Thank you for the reply. I went back and look to see if there was difference in our code... what I did discover is later in my code. This is not a great idea:
if($jobEnabled = "true")
{
🙂
Thank you for the help!
Very $true 😉
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply