Skip to content

Commit 7050c20

Browse files
authored
Change Get-Service to ignore errors, for when there's a service that's malformed or would otherwise tank the Get-Service command (#3650)
1 parent cd96869 commit 7050c20

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

DevCheck.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ function Test-TAEFService
755755
}
756756

757757
# Double-check the TAEF service is known as a service as far as Windows is concerned
758-
$service = Get-Service |Where-Object {$_.Name -eq "TE.Service"}
758+
$service = Get-Service -ErrorAction SilentlyContinue | Where-Object {$_.Name -eq "TE.Service"}
759759
if ([string]::IsNullOrEmpty($service))
760760
{
761761
Write-Host "TAEF service...Not Installed"
@@ -812,7 +812,7 @@ function Install-TAEFService
812812

813813
$args = '/install:TE.Service'
814814
$output = Run-Process $path $args
815-
$service = Get-Service |Where-Object {$_.Name -eq "TE.Service"}
815+
$service = Get-Service -ErrorAction SilentlyContinue | Where-Object {$_.Name -eq "TE.Service"}
816816
if ([string]::IsNullOrEmpty($service))
817817
{
818818
Write-Host "Install TAEF service...Failed"
@@ -845,7 +845,7 @@ function Uninstall-TAEFService
845845
$filename = Get-TAEFServiceImagePath
846846
$args = '/remove:TE.Service'
847847
$output = Run-Process $filename $args
848-
$service = Get-Service |Where-Object {$_.Name -eq "TE.Service"}
848+
$service = Get-Service -ErrorAction SilentlyContinue | Where-Object {$_.Name -eq "TE.Service"}
849849
if (-not([string]::IsNullOrEmpty($service)))
850850
{
851851
Write-Host "Uninstall TAEF service...Failed"
@@ -870,7 +870,7 @@ function Start-TAEFService
870870
}
871871

872872
$ok = Start-Service 'TE.Service'
873-
$service = Get-Service |Where-Object {$_.Name -eq "TE.Service"}
873+
$service = Get-Service -ErrorAction SilentlyContinue | Where-Object {$_.Name -eq "TE.Service"}
874874
if ($service.Status -ne "Running")
875875
{
876876
Write-Host "Start TAEF service...Failed"
@@ -893,7 +893,7 @@ function Stop-TAEFService
893893
return $false
894894
}
895895

896-
$service = Get-Service |Where-Object {$_.Name -eq "TE.Service"}
896+
$service = Get-Service -ErrorAction SilentlyContinue | Where-Object {$_.Name -eq "TE.Service"}
897897
if ($service -eq $null)
898898
{
899899
return 'NotFound'
@@ -902,7 +902,7 @@ function Stop-TAEFService
902902
{
903903
$ok = Stop-Service 'TE.Service'
904904
}
905-
$service = Get-Service |Where-Object {$_.Name -eq "TE.Service"}
905+
$service = Get-Service -ErrorAction SilentlyContinue | Where-Object {$_.Name -eq "TE.Service"}
906906
if ($service -eq $null)
907907
{
908908
return 'NotFound'

0 commit comments

Comments
 (0)