dbatools icon indicating copy to clipboard operation
dbatools copied to clipboard

Test Instant File Initialization Command

Open tboggiano opened this issue 3 years ago • 5 comments

Summarize Command's Functionality

Command to test to see if IFI is enable for the service account.

Is there a command that is similiar or close to what you are looking for?

No

Technical Details

Command exist to Get-DbaPrivilege and Set-DbaPrivilege, maybe one to just test like we do Power Plans since it is a recommended setting? I use this code to set if doesn't exist

$s = "server1"
$service = Get-DbaService -ComputerName $s | Where-Object { $_.ServiceType -eq "Engine" }
$priv = Get-DbaPrivilege -ComputerName $s | Where-Object { $_.InstantFileInitialization -eq $false -and $_.User -eq $service.StartName } 

if (!$priv) {
    Set-DbaPrivilege -ComputerName $s -Type IFI
}

Get-DbaPrivilege -ComputerName $s | Where-Object { $_.InstantFileInitialization -eq $false -and $_.User -eq $service.StartName } | Format-Table

tboggiano avatar Jun 16 '22 13:06 tboggiano

that makes sense. what do you propose the command name to be?

potatoqualitee avatar Jul 21 '22 12:07 potatoqualitee

First I thought about Test-DbaPrivilege with a parameter Privilege, but as we only have a solid best practice for InstantFileInitialization I now think Test-DbaInstantFileInitialization will be best. The hint to Test-DbaPowerPlan is very good, we can have a similar output. As input I would vote for ComputerName to test all instance on that computer and output one object per instance.

Example code:

function Test-DbaInstantFileInitialization {
    param(
        [DbaInstance[]]$ComputerName = $env:COMPUTERNAME,
        [PSCredential]$Credential,
        [switch]$EnableException
    )
    foreach ($computer in $ComputerName) {
        $services = Get-DbaService -ComputerName $computer -Credential $Credential -Type Engine
        $privileges = Get-DbaPrivilege -ComputerName $computer -Credential $Credential
        foreach ($service in $services) {
            $instantFileInitialization = ($privileges | Where-Object User -eq $service.StartName).InstantFileInitialization
            $isBestPractice = $instantFileInitialization -eq $true
            [PSCustomObject]@{
                ComputerName              = $service.ComputerName
                ServiceName               = $service.ServiceName
                InstanceName              = $service.InstanceName
                User                      = $service.StartName
                InstantFileInitialization = $instantFileInitialization
                IsBestPractice            = $isBestPractice
            }
        }
    }
}

Example output: image

andreasjordan avatar Jun 11 '23 10:06 andreasjordan

@tboggiano What do you think about the proposed command?

andreasjordan avatar Oct 29 '23 17:10 andreasjordan