0

I'm a newbie to powershell. I am working on a script which is not starting the service intermittently.

$sensuresult = Start-Process -Wait -FilePath $filepath -ArgumentList '/tasks="assocfiles,modpath" /quiet' -PassThru

Basically here we are trying to install a .msi package. Intermittently the above line fails.

Write-Host $sensuresult

Write-Host : The following exception occurred while retrieving the string: "Process has exited, so 
the requested information is not available."
At line:8 char:1
+ Write-Host $sensuresult
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Write-Host], ExtendedTypeSystemException
+ FullyQualifiedErrorId : 
ToStringPSObjectBasicException,Microsoft.PowerShell.Commands.WriteHostCommand

With the above error message I really do not know if Start-Process failed or Write-host.

Can I get some insights on why Start-Process is not installing the package intermittently and what is the best alternative way to do this.

Ashwin
  • 439
  • 1
  • 7
  • 23

1 Answers1

0

you can start process by first check the process is running or not.

#check service is running or not

$ServiceName = 'AppIDSvc'
$arrService = Get-Service -Name $ServiceName

while ($arrService.Status -ne 'Running')
{

    Start-Service $ServiceName
    write-host $arrService.status
    write-host 'Service starting'
    Start-Sleep -seconds 15
    $arrService.Refresh()
    if ($arrService.Status -eq 'Running')
    {
        Write-Host 'Service is now Running'
    }

}
pavithran G
  • 112
  • 2
  • 13
  • I have similar logic to start the service which will come after the installation of my .msi binary. I want to install my binary first. – Ashwin Jan 17 '20 at 10:24
  • @Ashwin,okay, normally when you try to run that msi, which exe is running ,because installation package all comes with .msi,need to know which one like PkgMgr.exe or wsua.exe or any other? – pavithran G Jan 17 '20 at 10:36
  • i'm trying to install 'sensu' – Ashwin Jan 17 '20 at 10:59