Skip to content

Instantly share code, notes, and snippets.

@kewalaka
Last active June 18, 2021 02:12
Show Gist options
  • Select an option

  • Save kewalaka/d13d3d1cf12a1e2857c9dbfdd80b45b9 to your computer and use it in GitHub Desktop.

Select an option

Save kewalaka/d13d3d1cf12a1e2857c9dbfdd80b45b9 to your computer and use it in GitHub Desktop.
This will set the service dependency of the SQL Service database engine to include netlogon and w32tm, this can help when a GMSA is used to make sure AD is available from the machine before the service is started.
$dependencies = @('netlogon', 'w32time')
# to remove:
#$dependencies = @('')
Get-CimInstance –Query 'select * from Win32_Service where name like "mssql%"' | foreach {
$serviceCimInstance = $_
$serviceName = $_.name
write-host "Apply service dependencies '$dependencies' to: $serviceName"
$changeServiceResult = Invoke-CimMethod `
-InputObject $serviceCimInstance `
-MethodName 'Change' `
-Arguments @{ ServiceDependencies = $Dependencies }
if ($changeServiceResult.ReturnValue -ne 0) {
throw "Failed to apply service dependencies '{0}' to: '{1}'. Error: {2}" -f $dependencies, $serviceName, $_.Exception
}
}
@kewalaka
Copy link
Copy Markdown
Author

kewalaka commented Apr 7, 2021

the dependencies on some database engines include the 'keyIso' service, which is hosted in the lsass.exe process.

the above also picks up the free text filter, the query needs some adjustment

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