Get Max Number of error log files

  • Creating Audit script to validate newly built sql server- as it's popular now- in PS. Do not have much experience with PS- learning on the fly- moving slowly but steadily. Stuck with validating Max N of Error Log files- that is 6 per default and it supposed to be changed to 30. In TSQL we can read registry (xp_instance_regread) but cannot find how to do this in "pure" PS  (would like to avoid running TSQL from inside PS). Any advice (or script) be greatly appreciated.

  • Yuri55 - Monday, March 11, 2019 6:19 PM

    Creating Audit script to validate newly built sql server- as it's popular now- in PS. Do not have much experience with PS- learning on the fly- moving slowly but steadily. Stuck with validating Max N of Error Log files- that is 6 per default and it supposed to be changed to 30. In TSQL we can read registry (xp_instance_regread) but cannot find how to do this in "pure" PS  (would like to avoid running TSQL from inside PS). Any advice (or script) be greatly appreciated.

    I take it you found Set-SqlErrorLog to set the number to 30. There is no equivalent get (as you probably found) other than for reading the error logs.
    I  used SMO to get it - some other "pure" SQL commands use SMO in their code. But that's the closest I found to getting the value without regread:
    $Server = 'YourServer'
    $srv = New-Object Microsoft.SqlServer.Management.Smo.Server $Server
    $srv.Settings.NumberOfLogFiles

    Sue

  • Thanks Sue- this is what Doctor ordered🙂
    Funny enough but I tried this way and did not get correct answer.
    Now tried it again- got 30- correct number.
    Thanks again

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

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