Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Finding Free Space per Data File with PowerShell Expand / Collapse
Author
Message
Posted Tuesday, May 10, 2011 9:52 PM


SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, May 20, 2014 5:57 PM
Points: 41, Visits: 122
Comments posted to this topic are about the item Finding Free Space per Data File with PowerShell

@SQLvariant
I have a PowerShell script for you.
Post #1106618
Posted Wednesday, May 11, 2011 6:35 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, July 22, 2014 3:44 PM
Points: 383, Visits: 568
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...
Post #1106839
Posted Wednesday, May 11, 2011 7:11 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Sunday, July 13, 2014 5:53 PM
Points: 94, Visits: 575
The hard way.... sheesh :)

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/
Post #1106880
Posted Wednesday, May 11, 2011 7:23 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, July 24, 2014 8:41 AM
Points: 861, Visits: 2,357
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.
Post #1106894
Posted Wednesday, May 11, 2011 7:33 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Sunday, July 13, 2014 5:53 PM
Points: 94, Visits: 575
@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/
Post #1106914
Posted Wednesday, May 11, 2011 7:36 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, July 24, 2014 8:41 AM
Points: 861, Visits: 2,357
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.
Post #1106920
Posted Wednesday, May 11, 2011 7:38 AM


SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, May 20, 2014 5:57 PM
Points: 41, Visits: 122
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


@SQLvariant
I have a PowerShell script for you.
Post #1106924
Posted Wednesday, May 11, 2011 8:31 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Sunday, July 13, 2014 5:53 PM
Points: 94, Visits: 575
@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/
Post #1107008
Posted Wednesday, May 11, 2011 9:06 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, May 12, 2011 4:24 PM
Points: 6, 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.
Post #1107049
Posted Wednesday, May 11, 2011 9:08 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, July 22, 2014 3:44 PM
Points: 383, Visits: 568
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...
Post #1107050
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse