0

I am running a dos command in PowerShell and getting the correct output. But I want to capture and process the output.

Example:

PS:>cmd.exe bpclimagelist.exe -t FULL
Backed Up         Expires       Files      KB     C Sched Type      Policy
----------------  ---------- -------- ----------- - --------------- ------------
08/25/2018 00:03  11/25/2018   179940    88589741 N Full Backup     WIN-01

I want to get backup dates from the table listed. Is there any way to achieve it ?

robinCTS
  • 4,407
Varun
  • 11

1 Answers1

-1

You don't have to call cmd.exe to run an executable in PS console.

If you pipe the output of your executable then you can have it as an array and you can start manipulating it.

To go through the lines of the output one by one:

PS:>bpclimagelist.exe -t FULL | Foreach-Object{ Write-Host $_ }; 

You can create an array type variable and work with it. Like:

PS:>$a = bpclimagelist.exe -t FULL; Write-Host $a[2]; 

will print out:

08/25/2018 00:03  11/25/2018   179940    88589741 N Full Backup     WIN-01

If you executable is not in the PATH and/or it contains a space then you should use the call operator (&) and quote the exe.

PS:>$a = &'C:\BCP Program Folder\bpclimagelist.exe' -t FULL; Write-Host $a[2];

Some more info.

bcs78
  • 904