forked from MikeFal/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExpand-SqlLogFile.ps1
29 lines (24 loc) · 958 Bytes
/
Expand-SqlLogFile.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#load assemblies
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
$ErrorActionPreference = 'Inquire'
function Expand-SqlLogFile{
param(
[string]$InstanceName = 'localhost',
[parameter(Mandatory=$true)][string] $DatabaseName,
[parameter(Mandatory=$true)][int] $LogSizeMB)
#Convert MB to KB (SMO works in KB)
[int]$LogFileSize = $LogSizeMB*1024
#Set base information
$srv = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server $InstanceName
$logfile = $srv.Databases[$DatabaseName].LogFiles[0]
$CurrSize = $logfile.Size
#grow file
while($CurrSize -lt $LogFileSize){
if(($LogFileSize - $CurrSize) -lt 8192000){$CurrSize = $LogFileSize}
else{$CurrSize += 8192000}
$logfile.size = $CurrSize
$logfile.Alter()
}
}
#Call the function
Expand-SqlLogFile -DatabaseName 'test' -LogSizeMB 35000