locked
setting JobServer.MaximumHistoryRows using powershell RRS feed

  • Question

  • Does anyone know the proper way of using SMO to set the MaximumHistoryRows?  This is what I have so far, but it errors out.

    [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
    	$s = New-Object ("Microsoft.SqlServer.Management.Smo.Server") $server
    	$s.JobServer.MaximumHistoryRows = 5000
    	$s.JobServer.MaximumHistoryRows.Alter()



    • Edited by Badpig522 Friday, March 8, 2013 1:38 AM
    Thursday, March 7, 2013 11:56 PM

Answers

  • I figured it out:

    [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
    	$s = New-Object ("Microsoft.SqlServer.Management.Smo.Server") $server
    	$s.jobserver | %{$_.MaximumHistoryRows = "5000"; $_.Alter()}
    	$s.JobServer.MaximumHistoryRows

    • Marked as answer by Badpig522 Wednesday, March 13, 2013 2:08 AM
    Wednesday, March 13, 2013 2:08 AM

All replies

  • What error do you get? Im no sql-guru, and perhaps you culd get a better answer in those forums? However...

    From what I can read in the docs (http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.agent.jobserver.maximumhistoryrows(v=sql.90).aspx) there is no need to run .Alter() after you set the value? Normally you should not need to post values.

    • Proposed as answer by Yan Li_ Tuesday, March 12, 2013 3:08 AM
    Sunday, March 10, 2013 5:46 PM
  • What error do you get? Im no sql-guru, and perhaps you culd get a better answer in those forums? However...

    From what I can read in the docs (http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.agent.jobserver.maximumhistoryrows(v=sql.90).aspx) there is no need to run .Alter() after you set the value? Normally you should not need to post values.

    I tried it without the alter() but didnt work with 
    $s.JobServer.MaximumHistoryRows = 5000
    Tuesday, March 12, 2013 9:17 PM
  • Could you post the error you are getting or are you just nog getting the expected result?
    Tuesday, March 12, 2013 10:03 PM
  • Could you post the error you are getting or are you just nog getting the expected result?

    No error, but when I check SQL Agent History, it did not change.

    I can see the setting using

    [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
    	$s = New-Object ("Microsoft.SqlServer.Management.Smo.Server") $server
    	$s.jobserver.MaximumHistoryRows

    • Edited by Badpig522 Wednesday, March 13, 2013 1:54 AM
    Wednesday, March 13, 2013 1:17 AM
  • I figured it out:

    [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
    	$s = New-Object ("Microsoft.SqlServer.Management.Smo.Server") $server
    	$s.jobserver | %{$_.MaximumHistoryRows = "5000"; $_.Alter()}
    	$s.JobServer.MaximumHistoryRows

    • Marked as answer by Badpig522 Wednesday, March 13, 2013 2:08 AM
    Wednesday, March 13, 2013 2:08 AM