Skip to content

Commit

Permalink
fixes #5210 (#5252)
Browse files Browse the repository at this point in the history
  • Loading branch information
potatoqualitee authored Mar 19, 2019
1 parent 026e6c1 commit 0f8805f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions functions/Remove-DbaDatabaseSafely.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -198,22 +198,26 @@ function Remove-DbaDatabaseSafely {
$serviceName = 'MSSQLSERVER'
} else {
$instance = $destserver.InstanceName
if ($instance.length -eq 0) { $instance = "MSSQLSERVER" }
$serviceName = "SQL Server Agent ($instance)"
if ($instance.length -eq 0) {
$instance = "MSSQLSERVER"
$serviceName = "SQLSERVERAGENT"
} else {
$serviceName = "SQLAgent`$$($instance)"
}
}

if ($Pscmdlet.ShouldProcess($destination, "Starting Sql Agent")) {
try {
$ipaddr = Resolve-SqlIpAddress $destserver
$agentservice = Get-Service -ComputerName $ipaddr -DisplayName $serviceName
$agentservice = Get-Service -ComputerName $ipaddr -Name $serviceName

if ($agentservice.Status -ne 'Running') {
$agentservice.Start()
$timeout = New-Timespan -seconds 60
$sw = [diagnostics.stopwatch]::StartNew()
$agentstatus = (Get-Service -ComputerName $ipaddr -DisplayName $serviceName).Status
$agentstatus = (Get-Service -ComputerName $ipaddr -Name $serviceName).Status
while ($AgentStatus -ne 'Running' -and $sw.elapsed -lt $timeout) {
$agentStatus = (Get-Service -ComputerName $ipaddr -DisplayName $serviceName).Status
$agentStatus = (Get-Service -ComputerName $ipaddr -Name $serviceName).Status
}
}
}
Expand Down

0 comments on commit 0f8805f

Please sign in to comment.