Skip to content

Instantly share code, notes, and snippets.

@SQLDBAWithABeard
Created September 30, 2018 06:29
Show Gist options
  • Save SQLDBAWithABeard/7a8866d7859759b15b833106d2c420a2 to your computer and use it in GitHub Desktop.
Save SQLDBAWithABeard/7a8866d7859759b15b833106d2c420a2 to your computer and use it in GitHub Desktop.
Setting services
$vms.ForEach{
Write-Output "Looking at VM $psitem"
# Get the Engine Services
$EngineServices = Get-DbaService -ComputerName $psitem -Type Engine
# Loop through the engine services
$EngineServices.ForEach{
$ComputerName = $psitem.ComputerName
$Name = $Psitem.ServiceName
$InstanceName = $psitem.InstanceName
Write-Output "Service $Name StartMode on $ComputerName is $($Psitem.startmode)"
# Set Start Mode to Manual
Set-Service -ComputerName $ComputerName -Name $Name -StartupType Manual
#Restart-Service
Get-Service -ComputerName $ComputerName -Name $Name| Restart-DbaService
$Service = Get-DbaService -ComputerName $ComputerName -InstanceName $InstanceName -Type Engine
Write-Output "Service $Name StartMode on $ComputerName is $($Service.startmode)"
}
}
@SQLDBAWithABeard
Copy link
Author

image

@SQLDBAWithABeard
Copy link
Author

$vms.ForEach{
$VM = $Psitem
Write-Output "Looking at VM $VM"

Get the Engine Services

$EngineServices = Get-Service  -ComputerName $VM -Name MSSQLSERVER

Loop through the engine services

    $EngineServices.ForEach{

        $Name = $Psitem.Name

        Write-Output "Service $Name StartMode on $ComputerName is $($Psitem.starttype)"
        # Set Start Mode to Manual
        Set-Service -ComputerName $VM -Name $Name  -StartupType Manual
        #Stop-Service
        Get-Service -ComputerName $VM -Name $Name| Stop-Service

        $Service = Get-Service  -ComputerName $VM -Name MSSQLSERVER

        Write-Output "Service $Name StartMode on $ComputerName is $($Service.starttype)"
    }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment