Get last reboot time for a host using powershell script

Here is how we can get the last reboot time for a host using powershell.

Get-WmiObject Win32_OperatingSystem -ComputerName <ip address> | foreach ($_) { [System.DateTime]::ParseExact($_.LastBootupTime.split('.')[0],'yyyyMMddHHmmss',$null) }


Note: You have to replace ip address or hostname to get output.

Delete files older than n days using Powershell script

 Here is a code to delete files older than N days where N refers number of days. In the code snippet below we are deleting files older than seven days.

$LastWrite = (Get-Date).AddDays(-7) 
 
Get-ChildItem "C:\temp" -Recurse | Where {$_.LastWriteTime -le $LastWrite} | foreach ($_) { Remove-Item $_.fullname}

How to schedule and automate backups of SQL Server databases in SQL Server Express

Anyone using SQL Server Express editions would have noticed that there is no way to schedule either jobs or maintenance plans because the SQL Server Agent is by default not included in these editions.

But what if those using Express editions would like to schedule and automate backups. Is there a way?

Yes, please read this article by Microsoft

Show Database ID in SQL Server

 The query below can retrieve database id by supplying the database name

-- Show database id using system view
 SELECT database_id FROM sys.databases
 WHERE name = '<db_name>';

-- Show database id using function
SELECT DB_ID('<db_name>');



Check for CPU Pressure in SQL Server

 The following query shows resource wait time and signal wait time both in value and in percentage. This is particularly useful in ascertaining if there is CPU pressure in your SQL Server. A higher signal wait time percentage can be a sign of CPU pressure or need for faster CPU on the server.

select
SUM(signal_wait_time_ms) as total_signal_wait_time_ms,
SUM(wait_time_ms - signal_wait_time_ms) as resource_wait_time_ms,
SUM(signal_wait_time_ms) * 1.0/SUM(wait_time_ms) *100 as signal_wait_percent,
SUM(wait_time_ms - signal_wait_time_ms) * 1.0 /SUM(wait_time_ms) * 100 as resource_wait_percent
from sys.dm_os_wait_stats