Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Finding Free Space per Data File with PowerShell


Finding Free Space per Data File with PowerShell

Author
Message
Aaron Nelson
Aaron Nelson
Old Hand
Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)

Group: General Forum Members
Points: 347 Visits: 172
Comments posted to this topic are about the item Finding Free Space per Data File with PowerShell

@SQLvariantI have a PowerShell script for you.
SQLHeap
SQLHeap
SSC-Addicted
SSC-Addicted (485 reputation)SSC-Addicted (485 reputation)SSC-Addicted (485 reputation)SSC-Addicted (485 reputation)SSC-Addicted (485 reputation)SSC-Addicted (485 reputation)SSC-Addicted (485 reputation)SSC-Addicted (485 reputation)

Group: General Forum Members
Points: 485 Visits: 737
Where can I get this cmdlet Get-SqlDatabase? Am using PSv2.0, SQL08, WinXP.

"The term 'Get-SqlDatabase' is not recognized as the name of a cmdlet,"

There is an exception to every rule, except this one...
WI-DBA
WI-DBA
SSC-Enthusiastic
SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)

Group: General Forum Members
Points: 186 Visits: 605
The hard way.... sheesh Smile

Pass in an SMO sql object and here you go! (doing the log files is that easy as well)

Function Get-DatabaseFilesBySpaceAvailable ([Microsoft.SqlServer.Management.Smo.Server] $SmoSqlServer
, [decimal] $sizeThreshold=0.85)
{
$sqlServer.Databases | Where-Object{$_.Status -eq "Normal"} `
| Select-Object FileGroups -ExpandProperty FileGroups `
| Select-Object Files -ExpandProperty Files `
| Where-Object {$_.MaxSize -gt -1} `
| Where-Object {$_.Size -gt ($_.MaxSize * $sizeThreshold)} `
| Select Name,UsedSpace,Size,MaxSize
}

Cheers
http://twitter.com/widba
http://widba.blogspot.com/
Nadrek
Nadrek
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1568 Visits: 2714
Hmmm... I usually just use SQL to find SQL data.

EXEC ('DBCC SQLPERF(logspace)'); - handles overall log information per database... but unless you have multiple Tlog files because you have critical drive space issues or for some other reason, that's not an issue. Runs on all DBs.

DBCC LOGINFO - shows VLFs in the Tlog (I particularly like watching Total Size/VLF; for very large Tlogs, this is more important). Runs on the current DB (so do dynamic SQL with a USE dbname; first).

DBCC SHOWFILESTATS - shows total and used extents for each data file. Runs on the current DB.
WI-DBA
WI-DBA
SSC-Enthusiastic
SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)

Group: General Forum Members
Points: 186 Visits: 605
@Nadrek - using SQL is the normal way for most of us.

At some point, you are going to have too many servers to manage doing on a server by server basis.

Utilizing a script that reads your central inventory server or simply a text file, you can check over every database file on every server in your enterprise - no multiple deployments or huge server groups to manage in SSMS. (I run a whole battery of checks nightly on every server, as I find something else, i just add it to my monitoring scripts in one location, the next day I have new info)

To me, that is the benefit.

Cheers
http://twitter.com/widba
http://widba.blogspot.com/
Nadrek
Nadrek
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1568 Visits: 2714
WI-DBA (5/11/2011)
@Nadrek - using SQL is the normal way for most of us.

At some point, you are going to have too many servers to manage doing on a server by server basis.

Utilizing a script that reads your central inventory server or simply a text file, you can check over every database file on every server in your enterprise - no multiple deployments or huge server groups to manage in SSMS. (I run a whole battery of checks nightly on every server, as I find something else, i just add it to my monitoring scripts in one location, the next day I have new info)

To me, that is the benefit.


That's why the script INSERTS INTO a central monitoring server from each server I manage, based on SQL Server Agent Jobs; I just read from the central monitoring server.

The SQL Server Agent Jobs and SP's are distributed using SSMS's Multiple Instance capability, based on Registered Server groups.
Aaron Nelson
Aaron Nelson
Old Hand
Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)

Group: General Forum Members
Points: 347 Visits: 172
Nadrek (5/11/2011)
WI-DBA (5/11/2011)
@Nadrek - using SQL is the normal way for most of us.

At some point, you are going to have too many servers to manage doing on a server by server basis.

Utilizing a script that reads your central inventory server or simply a text file, you can check over every database file on every server in your enterprise - no multiple deployments or huge server groups to manage in SSMS. (I run a whole battery of checks nightly on every server, as I find something else, i just add it to my monitoring scripts in one location, the next day I have new info)

To me, that is the benefit.


That's why the script INSERTS INTO a central monitoring server from each server I manage, based on SQL Server Agent Jobs; I just read from the central monitoring server.

The SQL Server Agent Jobs and SP's are distributed using SSMS's Multiple Instance capability, based on Registered Server groups.

Looks like you read my mind on the next article in the series :-)

@SQLvariantI have a PowerShell script for you.
WI-DBA
WI-DBA
SSC-Enthusiastic
SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)SSC-Enthusiastic (186 reputation)

Group: General Forum Members
Points: 186 Visits: 605
@Nadrek - Its a preference really, I don't like having lots of maintenance jobs on my servers, and when I come up with something new to check, the single deployment makes the whole process much quicker to deploy.

Cheers
http://twitter.com/widba
http://widba.blogspot.com/
Ofer Gal
Ofer Gal
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 13
On the SQL server I only have PS1
and the hard way gives me error:
Unexpected token 'in' in expression or statement.
At D:\Temp\freeInDB.ps1:11 char:40
+ $cmdStatement+=foreach ($DFileGroups in <<<< $db.FileGroups)

I just need to know how much unused space (GB) I have in 309GB database.

even a SQL script will do.
SQLHeap
SQLHeap
SSC-Addicted
SSC-Addicted (485 reputation)SSC-Addicted (485 reputation)SSC-Addicted (485 reputation)SSC-Addicted (485 reputation)SSC-Addicted (485 reputation)SSC-Addicted (485 reputation)SSC-Addicted (485 reputation)SSC-Addicted (485 reputation)

Group: General Forum Members
Points: 485 Visits: 737
Ofer Gal (5/11/2011)
On the SQL server I only have PS1
and the hard way gives me error:
Unexpected token 'in' in expression or statement.
At D:\Temp\freeInDB.ps1:11 char:40
+ $cmdStatement+=foreach ($DFileGroups in <<<< $db.FileGroups)

I just need to know how much unused space (GB) I have in 309GB database.

even a SQL script will do.


DBCC SQLPERF(logspace)

There is an exception to every rule, except this one...
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search