Tuesday, April 26, 2016

Powershell - Who rebooted my server?

If you work in a shared environment with multiple users having access and rights to your servers it is always good to be able to show who rebooted the server last. Here is a quick script to show you just that.

I like to run the script from the server because I don't always have rights with my account, but always have a service account that can access the server.

Ola Job Schedule Script

Many of you probably already use the Ola Hallengren (https://ola.hallengren.com/) backup and maintenance scripts. If you don't definitely look into them. The one complaint I had was that I had to schedule the jobs to be on our standard schedule after I installed the scripts. It took a few installs before I finally took the time and put together a quick script to create the schedule and attach it to the jobs. Now all I have to do is run the Ola script to add the jobs and underlying stored procedures and run my script to schedule them to the appropriate time. I took the 15 minute process of setup down to 2 minutes. All that time spent adding efficiency lets me get to lunch on time.

USE msdb
GO
 
 

EXEC sp_add_schedule
@schedule_name = N'Weekly-Ola' ,
@freq_type = 8,
@freq_interval = 64,
@active_start_time = 041500,
@freq_recurrence_factor = 1 ;


GO
 
 

EXEC sp_attach_schedule
@job_name = N'CommandLog Cleanup',
@schedule_name = N'Weekly-Ola' ;



GO
 
 

EXEC sp_attach_schedule
@job_name = N'Output File Cleanup',
@schedule_name = N'Weekly-Ola' ;



GO
 
 

EXEC sp_attach_schedule
@job_name = N'sp_delete_backuphistory',
@schedule_name = N'Weekly-Ola' ;



GO
 
 

EXEC sp_attach_schedule
@job_name = N'sp_purge_jobhistory',
@schedule_name = N'Weekly-Ola' ;



GO
 
 

EXEC sp_add_schedule
@schedule_name = N'Weekly-Ola_Integrity' ,
@freq_type = 8,
@freq_interval = 64,
@active_start_time = 191500,
@freq_recurrence_factor = 1 ;



GO
 
 

EXEC sp_attach_schedule

@job_name = N'DatabaseIntegrityCheck - SYSTEM_DATABASES',

@schedule_name = N'Weekly-Ola_Integrity' ;



GO
 
 

EXEC sp_attach_schedule
@job_name = N'DatabaseIntegrityCheck - USER_DATABASES',
@schedule_name = N'Weekly-Ola_Integrity' ;



GO
 
 

EXEC sp_add_schedule
@schedule_name = N'Weekly-Ola_Optimize' ,
@freq_type = 8,
@freq_interval = 1,
@active_start_time = 041500,
@freq_recurrence_factor = 1 ;



GO
 
 

EXEC sp_attach_schedule
@job_name = N'IndexOptimize - ALL_DATABASES',
@schedule_name = N'Weekly-Ola_Optimize' ;



GO
 
 

EXEC sp_add_schedule
@schedule_name = N'Weekly-Ola_Backup' ,
@freq_type = 8,
@freq_interval = 1,
@active_start_time = 191500,
@freq_recurrence_factor = 1 ;



GO
 
 

EXEC sp_attach_schedule
@job_name = N'DatabaseBackup - SYSTEM_DATABASES - FULL',
@schedule_name = N'Weekly-Ola_Backup' ;



GO
 
 

EXEC sp_attach_schedule
@job_name = N'DatabaseBackup - USER_DATABASES - FULL',
@schedule_name = N'Weekly-Ola_Backup' ;



GO
 
 

EXEC sp_add_schedule
@schedule_name = N'Hourly-Ola_Backup',
@freq_type = 4,
@freq_interval = 1,
@freq_subday_type = 8,
@freq_subday_interval=1,
@active_start_time=0,
@active_end_time=235959,
@freq_recurrence_factor = 1;


GO
 
 

EXEC sp_attach_schedule
@job_name = N'DatabaseBackup - ALL_DATABASES - LOG',
@schedule_name = N'Hourly-Ola_Backup' ;


GO
 
 




 
EXEC sp_add_schedule
@schedule_name = N'Nightly-Ola_Backup',
@freq_type = 8,
@freq_interval = 126,
@freq_subday_type=1,
@freq_subday_interval=0,
@freq_relative_interval=0,
@active_start_time = 191500,
@freq_recurrence_factor = 1 ;


GO
 
 

EXEC sp_attach_schedule
@job_name = N'DatabaseBackup - USER_DATABASES - DIFF',
@schedule_name = N'Nightly-Ola_Backup' ;


GO