Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SweetAsNZ/6bcf88c12ed7da21f6bed1e3402c3342 to your computer and use it in GitHub Desktop.
Save SweetAsNZ/6bcf88c12ed7da21f6bed1e3402c3342 to your computer and use it in GitHub Desktop.
Compare VMware Guests and Servers Backed Up By Veeam - Get A List of Servers That Aren't Backed Up
# Query VMWare for the List of All servers and compare with Veeam backups to see coverage
$Date = ((Get-Date -Format "yyyy-MM-dd_HHmm_K").Replace(":","-").Replace("+","-")).ToString() # _$($Date).csv" _$($Date).txt" # Date for use in Filenames with TZ
function Connect-VMWare{
$Server = 'vcenter'
$VMCli = (Get-Module VMware.PowerCLI -ListAvailable).Name
if($VMCli -ne 'VMware.PowerCLI'){
Write-Output "No VMWare CLI Found"
Install-Module VMware.PowerCLI -Scope AllUsers -AllowClobber #-Force
}
Import-Module VMware.PowerCLI
Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false -InvalidCertificateAction Ignore -Confirm:$False
$UPN = cmd /c whoami /upn
$Cred = (Get-Credential -UserName $UPN -Message "Password")
Connect-VIServer -Credential $Cred -Server $Server # Requires the Credential function to be run once
}
Connect-VMWare
# Gets VM Guests That Are Powered On
$VMs = Get-VM | Where {($_.PowerState -eq 'PoweredOn')}
$VMs | Select Name,NumCpu,MemoryGB | Export-CSV 'C:\SCRIPTS\Veeam\Get-VMwareGuestsAndVeeamBackedUpServers\VMs_PoweredOn.csv' -NoTypeInformation
# Gets Just the Name
$VMNames = ($VMs).Name
function Connect-Veeam{
[CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='low')]
Param
(
[Parameter(Mandatory=$false,ValueFromPipeline=$true,HelpMessage='Veeam Server Name')]
[string]$VeeamServer = 'Veeeam'
)
# Requires Install of Veeam Console e.g. on local server
#Get-Module -Name Veeam.Backup.PowerShell
Connect-VBRServer -Server $VeeamServer
}
Connect-Veeam
function Get-BackedUpServers{
# Gets Scheduled Jobs
$Jobs = Get-VBRJob | Where {($_.IsScheduleEnabled -eq $true)}
# Gets Included VMWare Guests Server
$BackedUpServers = ($Jobs | Get-VBRJobObject | Where-Object {$_.Type -eq 'Include'} | Sort Name).Name | Get-Unique
# Compares VmWare Guests That Are Powered On
$BackedUp = Compare-Object -ReferenceObject ($VMNames) -DifferenceObject ($BackedUpServers)
# Excludes SMB backups from the list
$NotBackedUp = ($BackedUp | Where {($_.SideIndicator -eq "=>") -and ($_.InputObject -notlike "\\*\*")} ).InputObject; $NotBackedUp
$NotBackedUp | Export-CSV "C:\SCRIPTS\Veeam\Get-VMwareGuestsAndVeeamBackedUpServers\ServersInVMWareNotBackedUp_$($Date).csv" -NoTypeInformation
}
Get-BackedUpServers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment