Sqlserver-dba.com

Free space on drives using Powershell

This script  using Powershell , takes a  list of SQL Servers , iterates through
the list and returns the results from the procedure : master.dbo.xp_fixeddrives.
Run this script as a standalone script or as part of a more comprehensive health monitoring snapshot

Depending on your security architecture , there may be a requirement to adjust the security method used to authenticate on the SQL Server

############START#################

foreach ($svr in get-content "C:\MySQLServers.txt"){
    $dt = new-object "System.Data.DataTable"
    $cn = new-object System.Data.SqlClient.SqlConnection >
"server=$svr;database=master;Integrated Security=sspi"
    $cn.Open()
    $sql = $cn.CreateCommand()
    $svr
    $sql.CommandText = "EXEC master.dbo.xp_fixeddrives"
    $rdr = $sql.ExecuteReader()
    $dt.Load($rdr)
    $cn.Close()
    $dt | Format-Table -autosize
}

##############FINISH########################

Source:Jack Vamvas (http://www.sqlserver-dba.com)
Author: Jack Vamvas (http://www.sqlserver-dba.com)

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact