Skip to content
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

Fixed math for StepSize in Invoke-DbaDbShrink #5040

Merged
merged 1 commit into from
Feb 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions functions/Invoke-DbaDbShrink.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ function Invoke-DbaDbShrink {
return
}

if ((Test-Bound -ParameterName StepSize) -and $stepsize -lt 1024) {
if ((Test-Bound -ParameterName StepSize) -and $StepSize -lt 1024) {
Stop-Function -Message "StepSize is measured in bits. Did you mean $StepSize bits? If so, please use 1024 or above. If not, then use the PowerShell bit notation like $($StepSize)MB or $($StepSize)GB"
return
}

if ($stepsize) {
$StepSizeKB = ([dbasize]($StepSize)).Kilobyte
if ($StepSize) {
$stepSizeKB = ([dbasize]($StepSize)).Kilobyte
}
$StatementTimeoutSeconds = $StatementTimeout * 60

Expand Down Expand Up @@ -248,12 +248,12 @@ function Invoke-DbaDbShrink {

$shrinkGap = ($startingSize - $desiredFileSize)
Write-Message -Level Verbose -Message "ShrinkGap: $([int]$shrinkGap) KB"
Write-Message -Level Verbose -Message "Step Size: $(([dbasize]$StepSize).Megabyte) MB"
Write-Message -Level Verbose -Message "Step Size: $($stepSizeKB) KB"

if ($StepSizeKB -and ($shrinkGap -gt $stepSizeKB)) {
if ($stepSizeKB -and ($shrinkGap -ge $stepSizeKB)) {
for ($i = 1; $i -le [int](($shrinkGap) / $stepSizeKB); $i++) {
Write-Message -Level Verbose -Message "Step: $i"
$shrinkSize = $startingSize - (($StepSizeKB * 1024 * 1024) * $i)
Write-Message -Level Verbose -Message "Step: $i / $([int](($shrinkGap) / $stepSizeKB))"
$shrinkSize = $startingSize - ($stepSizeKB * $i)
if ($shrinkSize -lt $desiredFileSize) {
$shrinkSize = $desiredFileSize
}
Expand Down