0

I have script that checks every 24 hours locally on server the status of all backup jobs along more details.

I want that script to check all my servers, lets say: "SRV1", "SRV2", "SRV3"

How can i manage that?

Here's the script:

$date = (Get-Date).AddHours(-24)
$sessions = Get-VBRComputerBackupJobSession
foreach ($PBackup_job in (Get-VBRComputerBackupJob | Select Name)) {
    $PBackup_job_name = $PBackup_job.Name
    write "------------   Physical Server Backup Job Name : $PBackup_job_name   ------------"
    $sessions | where {$_.CreationTime -ge $date} | sort CreationTime | Select CreationTime, endtime, result, state | Format-Table
    }
StackBuck
  • 789
  • 1
  • 12
  • 34

1 Answers1

0

Although I cannot test this myself, I think you could do that using Invoke-Command like below:

$servers = "SRV1", "SRV2", "SRV3"
# set the credentials for admin access on the servers
$cred    = Get-Credential 'Please enter your admin credentials'

$result  = Invoke-Command -ComputerName $servers -Credential $cred -ScriptBlock {
    $date     = (Get-Date).AddHours(-24).Date
    $sessions = Get-VBRComputerBackupJobSession
    foreach ($PBackup_job in (Get-VBRComputerBackupJob)) {
        $sessions | Where-Object {$_.CreationTime -ge $date} | 
        Sort-Object CreationTime | 
        Select-Object @{Name = 'Server'; Expression = {$env:COMPUTERNAME}}, 
                      @{Name = 'BackupJobName'; Expression = {$PBackup_job.Name}}, 
                      CreationTime, endtime, result, state
        }
}

# remove the extra properties PowerShell added and save to CSV
$result = $result | Select-Object * -ExcludeProperty PS*, RunSpaceId

# output on screen
$result | Format-Table -AutoSize

# write to file
$result | Export-Csv -Path 'X:\Somewhere\BackupJobs.csv' -NoTypeInformation
Theo
  • 57,719
  • 8
  • 24
  • 41
  • When i execute the code i got credentials popup along with error: "Connecting to remote server SRV failed with the following error message : The WinRM client cannot process the request." – StackBuck Jun 21 '22 at 08:01
  • @StackBuck [Enable WinRM](https://learn.microsoft.com/en-us/troubleshoot/windows-server/remote/how-to-enable-windows-remote-shell) – Theo Jun 21 '22 at 14:22
  • I cant because it makes the servers vulnerable to attacks – StackBuck Jun 26 '22 at 10:20