-1

I am trying to change from using a cmd file to Powershell script so that I can include email alerting on failure. Current script looks like this:

"C:\Program Files\Actian\PSQL\PBA\BIN\pvbackup64.exe" -on
"C:\Program Files\Actian\PSQL\PBA\BIN\pvbackup64.exe" -status > $Log

I tried using Start-Process, but cannot get it working

Jacques
  • 21
  • 4
  • 1
    Hw can we assist you with your `Start-Process` command, if you've not shown us it, or told us what happens when you run it? Have you Entered `Get-Help Start-Process -Full` in a Windows PowerShell Prompt? _(to learn how to use the command)_. – Compo Nov 19 '20 at 22:54
  • Nothing happens. I will try the command to find out more. Thank you for your help – Jacques Nov 20 '20 at 00:29
  • For synchronously calling console applications, `Start-Process` isn't the right tool. For _syntactic_ reasons, PowerShell requires executable paths that are _quoted_ and / or contain _variable references_ to use `&`, the call operator. See [this answer](https://stackoverflow.com/a/64413759/45375) to the linked duplicate. – mklement0 Nov 20 '20 at 00:42

1 Answers1

1

What you need is the invocation operator (&):

$Log = "path\to\log.file"
& "C:\Program Files\Actian\PSQL\PBA\BIN\pvbackup64.exe" -on
& "C:\Program Files\Actian\PSQL\PBA\BIN\pvbackup64.exe" -status > $Log

Beware that the > file redirection operator in Windows PowerShell always uses unicode encoding, and you might want to replace it with the Set-Content cmdlet instead:

$Log = "path\to\log.file"
& "C:\Program Files\Actian\PSQL\PBA\BIN\pvbackup64.exe" -on
& "C:\Program Files\Actian\PSQL\PBA\BIN\pvbackup64.exe" -status |Set-Content -LiteralPath $Log
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206