Category Archives: PowerShell

PowerShell – Find top 10 Largest files of a local or remote Drive

Name of the function: Get-LargestFile The Input parameters are ServerName and Drive. Function call PS:\>Get-LargestFile -server HQDB001-drive e In this case HQDB001[ServerName] and E[Drive] **************************** Code:- *********************** Function Get-LargestFile { Param([String]$server,[char]$drive) Get-ChildItem \\$server\$drive$ -recurse -force -ErrorAction SilentlyContinue | Select-object Name,DirectoryName, @{Label=’Size’;Expression={($_.Length/1GB).ToString(‘F04′)}} … Continue reading

Posted in PowerShell | 2 Comments

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

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

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