$out = "G:\WEB-SERVER\htdocs\AttendanceHub\ZKTecoSyncService-V2\_deployment\sc_results.txt" $exe = "G:\WEB-SERVER\htdocs\AttendanceHub\ZKTecoSyncService-V2\publish\AttendanceHub.Sync.Host.exe" $r = New-Object System.Collections.Generic.List[string] $r.Add("elevatedAt=$(Get-Date -Format o)") $r.Add("---- sc config binPath") $r.Add((& sc.exe config ZKTecoSyncService binPath= "`"$exe`"" 2>&1 | Out-String)) $r.Add("---- sc config start= auto") $r.Add((& sc.exe config ZKTecoSyncService start= auto 2>&1 | Out-String)) $r.Add("---- sc start") $r.Add((& sc.exe start ZKTecoSyncService 2>&1 | Out-String)) Start-Sleep -Seconds 8 $r.Add("---- sc query") $r.Add((& sc.exe query ZKTecoSyncService 2>&1 | Out-String)) try { $s = Get-Service ZKTecoSyncService; $r.Add("Get-Service State=$($s.Status) StartType=$($s.StartType) DisplayName=$($s.DisplayName)") } catch { $r.Add("Get-Service ERROR: $($_.Exception.Message)") } Set-Content -Path $out -Value ($r -join "`r`n") -Encoding UTF8