Monthly Archives: April 2013

PowerShell and SQL – Easy and Different Ways to Find Number of Rows of all Tables in a database

SQL Example: DECLARE @TableRowsCount table ( Tablename varchar(50), cnt int) insert into @TableRowsCount EXEC sp_MSforeachtable @command1=” select ‘?’,count(*) from ?” select * from @TableRowsCount PowerShell Example: Load SQL PowerShell by typing “SQLPS” in PowerShell console PS:\>SQLPS Change Directory to the … Continue reading

Posted in PowerShell, SQL | Leave a comment

SQL 2005 or above – Find Transaction Rate on a busy OLTP Database

Change Database name of a below mentioned query DECLARE @cntr_value1 bigint DECLARE @cntr_value2 bigint SELECT ‘BEFORE’ SELECT @cntr_value1 = cntr_value FROM sys.dm_os_performance_counters WHERE counter_name = ‘transactions/sec’ AND object_name = ‘SQLServer:Databases’ AND instance_name =’ABCD‘ /*DB NAME*/ select ‘ABCD’ DBNAME, @cntr_value1 ‘Lower … Continue reading

Posted in SQL | Leave a comment

PowerShell – CHECK, START and STOP SQL Services of a remote servers

Replace a valid server name in the following examples. Try to do a testing on your local machine and understand before you execute it on any Production Server. Example 1: Find all SQL related services on HQSQ001 Get-Service -ComputerName HQSQ001 | … Continue reading

Posted in PowerShell | 5 Comments

Find SQL Server Installation – Date and Time – 2005 Onwards

SELECT create_date as ‘SQL Server Install Date’ FROM sys.server_principals WHERE name=’NT AUTHORITY\SYSTEM’

Posted in SQL | Tagged | Leave a comment

PowerShell – Pattern Search – Local or Remote Folder

#Description : List all the files of a local or remote drive, run this PowerShell script using PowerShell-ISE.exe for better execution and output. Steps:- Copy the content and  paste it in Get-AllFilesSearchbyPattern.PS1  and Execute. #Input Parameter List – Server Name, Drive … Continue reading

Posted in PowerShell | Leave a comment

A man is a hero…

A man is a hero not because he is braver than anyone else; he is hero because he is brave for 10 minutes longer

Posted in Uncategorized | Leave a comment