From d7fdf162be1ae72d6ba923b17dbce71f4d8c3cf7 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 7 Dec 2017 16:06:20 +0300 Subject: [PATCH 1/3] Touch Invoke-DbaDatabaseShrink * standardized swich comparasion in IF * removed Update Usage for LOG shrink * removed unused variable $StatementTimeoutMinutes --- functions/Invoke-DbaDatabaseShrink.ps1 | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/functions/Invoke-DbaDatabaseShrink.ps1 b/functions/Invoke-DbaDatabaseShrink.ps1 index c35d4925a3..ef365be4cc 100644 --- a/functions/Invoke-DbaDatabaseShrink.ps1 +++ b/functions/Invoke-DbaDatabaseShrink.ps1 @@ -145,8 +145,6 @@ Shrinks all databases on SQL2012 (not ideal for production) $FileType = 'Log' } - $StatementTimeoutMinutes = $StatementTimeout * 60 - $sql = "SELECT indexstats.avg_fragmentation_in_percent FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, NULL) AS indexstats @@ -246,7 +244,6 @@ Shrinks all databases on SQL2012 (not ideal for production) $db.LogFiles.Shrink($PercentFreeSpace, $ShrinkMethod) $db.Refresh() Write-Message -Level Verbose -Message "Recalculating space usage" - if ($False -eq $ExcludeUpdateUsage){$db.RecalculateSpaceUsage()} $success = $true $notes = $null } @@ -266,7 +263,7 @@ Shrinks all databases on SQL2012 (not ideal for production) } $db.Refresh() Write-Message -Level Verbose -Message "Recalculating space usage" - if ($False -eq $ExcludeUpdateUsage){$db.RecalculateSpaceUsage()} + if (-not $ExcludeUpdateUsage) { $db.RecalculateSpaceUsage() } $success = $true $notes = $null } catch { @@ -280,7 +277,7 @@ Shrinks all databases on SQL2012 (not ideal for production) $db.Shrink($PercentFreeSpace, $ShrinkMethod) $db.Refresh() Write-Message -Level Verbose -Message "Recalculating space usage" - if ($False -eq $ExcludeUpdateUsage){$db.RecalculateSpaceUsage()} + if (-not $ExcludeUpdateUsage) { $db.RecalculateSpaceUsage() } $success = $true $notes = $null } From 682e588bf29b0cf65d08ec97bfe982a76be0cad2 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 8 Dec 2017 09:46:31 +0300 Subject: [PATCH 2/3] Fixing weird bug with timeoutassigment * changed variable name to $StatementTimeoutSeconds * assign proper value to ConnectionContext.StatementTimeout --- functions/Invoke-DbaDatabaseShrink.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/functions/Invoke-DbaDatabaseShrink.ps1 b/functions/Invoke-DbaDatabaseShrink.ps1 index ef365be4cc..facb1a3ff8 100644 --- a/functions/Invoke-DbaDatabaseShrink.ps1 +++ b/functions/Invoke-DbaDatabaseShrink.ps1 @@ -145,6 +145,8 @@ Shrinks all databases on SQL2012 (not ideal for production) $FileType = 'Log' } + $StatementTimeoutSeconds = $StatementTimeout * 60 + $sql = "SELECT indexstats.avg_fragmentation_in_percent FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, NULL) AS indexstats @@ -188,7 +190,7 @@ Shrinks all databases on SQL2012 (not ideal for production) else { Write-Message -Level Verbose -Message "Changing statement timeout to $StatementTimeout minutes" } - $server.ConnectionContext.StatementTimeout = $StatementTimeout + $server.ConnectionContext.StatementTimeout = $StatementTimeoutSeconds $dbs = $server.Databases | Where-Object { $_.IsSystemObject -eq $false } From 4b6f7f5f3b1fe18b12285f790168d59a17c1b8ef Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 8 Dec 2017 10:18:21 +0300 Subject: [PATCH 3/3] Small parameter description change --- functions/Invoke-DbaDatabaseShrink.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/Invoke-DbaDatabaseShrink.ps1 b/functions/Invoke-DbaDatabaseShrink.ps1 index facb1a3ff8..fcb3c03c1d 100644 --- a/functions/Invoke-DbaDatabaseShrink.ps1 +++ b/functions/Invoke-DbaDatabaseShrink.ps1 @@ -71,7 +71,7 @@ Specifies the files types that will be shrunk Exclude statistics about fragmentation .PARAMETER ExcludeUpdateUsage -Skips DBCC UPDATE USAGE for database +Exclude DBCC UPDATE USAGE for database .PARAMETER WhatIf Shows what would happen if the command were to run