-
-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 320 fix? #623
base: development
Are you sure you want to change the base?
Issue 320 fix? #623
Changes from 1 commit
2c772f8
ddfeb1a
d08933e
e9977c7
6780cf3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
function Get-DatabaseDiskFreeSpace { | ||
<# | ||
.SYNOPSIS | ||
Returns if there is enough diskspace for the instance to grow for one cycle. | ||
|
||
.DESCRIPTION | ||
Returns if there is enough diskspace for the instance to grow for one cycle. | ||
The checks is disk based, so the check will be done for each disk where the databases stores files. | ||
|
||
.NOTES | ||
Tags: Database, FileSize, FileGrowth | ||
Author: Reitse Eskens (@2meterDBA) | ||
|
||
.PARAMETER SqlInstance | ||
The Instance for which you want to perform your check | ||
|
||
.PARAMETER SqlCredential | ||
Credentials to connect to the SQL Server instance if the calling user doesn't have permission | ||
|
||
.EXAMPLE | ||
Get-DatabaseDiskFreeSpace -SqlInstance sql2016 | ||
#> | ||
|
||
[CmdletBinding()] | ||
|
||
param ( | ||
[parameter(ValueFromPipeline)] | ||
[DbaInstanceParameter[]]$SqlInstance, | ||
[PSCredential]$SqlCredential | ||
) | ||
|
||
|
||
begin { | ||
<# | ||
Step one. Get de free diskspace from the disks where Sql Server is parking it's files. | ||
The line will get the data from the chosen instance. Next the result is filtered down to just the drive letter for the summation later on. | ||
The -unique is used to limit the results. We get a result line for each database file, but all we need is a drive and the free space. | ||
|
||
#> | ||
|
||
$DiskFreeSpace = Get-DbaDbFile -SqlInstance REITSE-PC\VANTAGE | SELECT @{label='DriveLetter';Expression={$_.PhysicalName.substring(0,3)}}, VolumeFreeSpace |Sort-Object -Property Driveletter -Unique | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please can this have a try catch |
||
<# | ||
Step two. Determine per drive letter how much growth can be expected. | ||
Same concept as the first step, but now we're looking at the file growth. | ||
#> | ||
|
||
$FileGrowth = Get-DbaDbFile -SqlInstance REITSE-PC\VANTAGE | SELECT @{label='DriveLetter';Expression={$_.PhysicalName.substring(0,3)}}, NextGrowthEventSize | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please can this have a try catch |
||
<# | ||
Step three, summation of the disk growth | ||
#> | ||
|
||
|
||
$calc = $FileGrowth | Group-Object -Property Driveletter | ForEach-Object -Process { | ||
$Sum = $_.group | measure -Sum -Property NextGrowthEventSize | ||
[pscustomobject]@{DriveLetter=$_.Name ; value = $Sum.Sum} | ||
} | ||
|
||
<# | ||
Step three and a bit, because the summation results in something else than GB, the result is rebuilt to gigabytes | ||
shaneis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#> | ||
|
||
|
||
$CalcInGB = $calc | select DriveLetter, @{name="GrowthInGB" ; Expression={[math]::Round($_.value/1GB, 2)}} | ||
|
||
<# | ||
Now for the interesting part. Time to compare the results! | ||
For each line in the disk free space results, the expected growth will be checked. | ||
If the drives are the same, the comparison will take place and the result will be shown. | ||
#> | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is super, can we create a pscustomobject here so that we have something like ComputerName | SQLInstance | DriveLetter | FreeSpace | Growth | GrowthAchievable |
||
$DiskFreeSpace | ForEach-Object -Process { | ||
if($_.DriveLetter -cin $CalcInGB.DriveLetter) | ||
{ | ||
$localDisk = $_.DriveLetter | ||
$localFileSize = $_.VolumeFreeSpace | ||
$CalcInGB | ForEach-Object -Process { | ||
If($_.DriveLetter -eq $localDisk) | ||
{ | ||
if($_.GrowthInGB -ge $localFileSize ) | ||
{ | ||
Write-Host $localDisk 'Don't panic, don't Panic. Time to grow the this disk mr Mainwairing' | ||
} | ||
else | ||
{ | ||
Write-Host $localDisk 'Fall in chaps, if you please... yes yes yes you look very smart' | ||
} | ||
|
||
} | ||
} | ||
} | ||
else | ||
{ | ||
Write-Host $_.DriveLetter 'Pike! You stupid Boy!' | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get the free
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the comments in the code :-) Thank you :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo fixed