Skip to content

Get last reboot time

systeminfo | findstr /C:”System Boot Time” $BootTime = (systeminfo | find “System Boot Time:”).Replace(“System Boot Time:”,””).Trim() $BootTime $Uptime = (Get-Date) – [datetime]$BootTime $Uptime

Display users using sp_who, sp_who2 – SQL Server

— see users logged – table variable example DECLARE @whotable TABLE ( SPID INT, Status VARCHAR(1000) NULL, Login SYSNAME NULL, HostName SYSNAME NULL, BlkBy SYSNAME NULL, DBName SYSNAME NULL, Command VARCHAR(1000) NULL, CPUTime INT NULL,… 

Query Connection Data – SQL Server

use [master] go SELECT DB_NAME(dbid) as DBName, COUNT(dbid) as NumberOfConnections, loginame as LoginName FROM sys.sysprocesses WHERE dbid > 0 GROUP BY dbid, loginame order by 2 desc SELECT * FROM sys.dm_exec_sessions where host_name is not… 

Find a column in a SQL Server Database

use [XYZ] — your database name go select name, type_desc from sys.all_objects where object_id in (select object_id from sys.all_columns where upper(name)='<your column name>’) go

Get Size of all tables in a SQL Server Database

use [<dbname>] go SELECT t.NAME AS TableName, s.Name AS SchemaName, p.rows AS RowCounts, SUM(a.total_pages) * 8 AS TotalSpaceKB, SUM(a.used_pages) * 8 AS UsedSpaceKB, (SUM(a.total_pages) – SUM(a.used_pages)) * 8 AS UnusedSpaceKB FROM sys.tables t INNER JOIN… 

Launch Admin Tools from Windows Command Line

Many of the Windows admin tools can be quickly accessed by launching them from an administrator command prompt. AD Domains and Trusts domain.msc Active Directory Management admgmt.msc AD Sites and Serrvices dssite.msc AD Users and…