Last active
November 23, 2022 22:30
-
-
Save SweetAsNZ/a00c63dfe47695f693141a2bfb3d6bec to your computer and use it in GitHub Desktop.
Check if a Server is Being Snapshotted in a Veeam backup and What Job a Server is Being Backed up In
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.Synopsis | |
Checks Veeam Snapshot Backups For A Given Server Name. Also finds the Job that Server is being snapped in | |
.DESCRIPTION | |
.EXAMPLE | |
Check-ServerBackup -ComputerName Server01 | |
.EXAMPLE | |
Check-ServerBackup -ConnectVeeamServer:$true -ReloadQuery:$true -ComputerName Server02 | |
#> | |
function Check-ServerBackup | |
{ | |
[CmdletBinding()] | |
Param | |
( | |
[Parameter(Mandatory=$true)] | |
[string]$ComputerName | |
, | |
[Parameter(Mandatory=$false,HelpMessage='Speeds Up Script Run Time')] | |
[bool]$ConnectVeeamServer = $false | |
, | |
[Parameter(Mandatory=$false,HelpMessage='Speeds Up Script Run Time')] | |
[bool]$ReloadQuery = $false | |
, | |
[Parameter(Mandatory=$false)] | |
[bool]$Testing = $false | |
) | |
if($ConnectVeeamServer -eq $true){ | |
. C:\SCRIPTS\VEEAM\Connect-Veeam\Connect-Veeam.ps1 # Load Function or run 'Connect-VBRServer -Server VeeamServer1.domain.local' | |
Connect-Veeam # Run Function | |
} | |
if($ReloadQuery) | |
{ | |
$Jobs = Get-VBRJob | Where {($_.IsScheduleEnabled -eq $true)} | Select Name,Id | |
# Gets Included VMWare Guests Server. This If is to speed up queries once loaded initially | |
$BackupJobs = ($Jobs).Name | Get-VBRJobObject | Where-Object {($_.Type -eq 'Include') -and ($_.TypeDisplayName -eq "Virtual Machine")} | Sort Name | |
} | |
$BackedUpServers = ($BackupJobs).Name | Get-Unique | |
########################################## | |
# Check if a Server is backed up | |
if($Testing){ | |
$ComputerName = Read-Host "Server to Check if it is in VM snap backups?" | |
} | |
$Found = $BackupJobs | Where {($_.Name -eq $ComputerName)} | Select Name,JobID ; $Found | |
$JobName = $Jobs | Sort ID | Where {($_.ID -eq ($Found).JobID)} #; $JobName | |
if($Found){ | |
Write-Host -f Green "Server: $($Found.Name) found in Job: $($JobName.Name)" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment