powershellveeam

robocopy match directories from text file


I would like to automate the copy of all "Stopped" Backup Jobs from my Veeam server to another location, about that:

Get-VBRJob | Out-String -Stream | Select-String "Stopped"; Get-Date -Format "#dddd dd/MM/yyyy" > /logs/stopped_jobs.txt

How can I take the output list in "/logs/stopped_jobs.txt" and use that for input in robocopy to match the source directories? The directories (D:/Backup/...) has the same name of the jobs in the list.

The example output of "Get-VBRJob" is it:

<Job Name> <Type> <State> <Latest result> <Notes>

Solution

  • You're not showing the export of the output into "/logs/stopped_jobs.txt" with the commands you've posted. Since PS returns objects it doesn't make much sense to stringify it, parse the string, then do something with it when you can work with the properties themselves.

    Get-VBRJob | Where-Object -Property 'State' -EQ 'Stopped' | # filter for objects with a state of "Stopped"
        ForEach-Object -Begin {
            $parent = 'D:\Backup\' 
        } -Process {
            $source = Join-Path -Path $parent -ChildPath $_.'Job Name' # join the parent path with the child path to make the source from "Job Name"
            RoboCopy.exe $source '\\Path\destination' /s 
        }