PowerShell script exchange
Post Reply
flavor4real
Expert
Posts: 205
Liked: 5 times
Joined: Nov 22, 2010 7:57 pm
Full Name: DS
Contact:

Compare vSphere VM's to Backed up VM's

Post by flavor4real »

Hello,
I found the following script in the forum and tried to work with it. There is a small error (below):

Code: Select all

asnp "VeeamPSSnapIn" -ErrorAction SilentlyContinue

####################################################################
# Configuration
# vCenter server
$vcenter = "SERVERNAME"
# To Exclude VMs from report add VM names to be excluded as follows
# $excludevms=@("vm1","vm2")
$excludevms=@()
####################################################################

$vcenterobj = Get-VBRServer -name $vcenter

# Build hash table with excluded VMs
$excludedvms=@{}
foreach ($vm in $excludevms) {
    $excludedvms.Add($vm, "Excluded")
}

# Get a list of all VMs from vCenter and add to hash table, assume Unprotected
$vms=@{}
foreach ($vm in (Find-VBRObject -server $vcenterobj | Where-Object {$_.Type -eq "VirtualMachine"}))  {
    if (!$excludedvms.ContainsKey($vm.Name)) {
        $vms.Add($vm.Name, "Unprotected")
    }
}

# Find all backup job sessions that have ended in the last 24 hours
$vbrsessions = Get-VBRBackupSession | Where-Object {$_.JobType -eq "Backup" -and $_.EndTime -ge (Get-Date).addhours(-24)}

# Find all successfully backed up VMs in selected sessions (i.e. VMs not ending in failure) and update status to "Protected"
foreach ($session in $vbrsessions) {
    foreach ($vm in ($session.gettasksessions() | Where-Object {$_.Status -ne "Failed"} | ForEach-Object { $_ })) {
        if($vms.ContainsKey($vm.Name)) {
            $vms[$vm.Name]="Protected"
        }
    }
}

# Output VMs in color coded format based on status.
foreach ($vm in $vms.Keys)
{
  if ($vms[$vm] -eq "Protected") {
      write-host -foregroundcolor green "$vm is backed up"
  } else {
      write-host -foregroundcolor red "$vm is NOT backed up"
  }
}

The error I'm receiving is:

Code: Select all

PS C:\Users\xxxxxx\Desktop> C:\Users\xxxxxx\Desktop\New Text Document.ps1
Get-VBRServer : A parameter cannot be found that matches parameter name 'name'.
At C:\Users\xxxxxx\Desktop\New Text Document.ps1:12 char:34
+ $vcenterobj = Get-VBRServer -name <<<<  $vcenter
    + CategoryInfo          : InvalidArgument: (:) [Get-VBRServer], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Veeam.Backup.PowerShell.Command.GetVBRServer
 
Find-VBRObject : Cannot validate argument on parameter 'Server'. The argument is null. Supply a non-null argument and try 
the command again.
At C:\Users\xxxxxx\Desktop\New Text Document.ps1:22 char:40
+ foreach ($vm in (Find-VBRObject -server <<<<  $vcenterobj | Where-Object {$_.Type -eq "VirtualMachine"}))  {
    + CategoryInfo          : InvalidData: (:) [Find-VBRObject], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Command.FindVBRObject
 
You cannot call a method on a null-valued expression.
At C:\Users\xxxxxx\Desktop\New Text Document.ps1:33 char:46
+     foreach ($vm in ($session.gettasksessions <<<< () | Where-Object {$_.Status -ne "Failed"} | ForEach-Object { $_ })) 
{
    + CategoryInfo          : InvalidOperation: (gettasksessions:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 

_______________________________________________________________________________________________________________________

I'm using the correct spelled vCenter name and tried the FQDN What could be the problem?
tsightler
VP, Product Management
Posts: 6012
Liked: 2843 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Compare vSphere VM's to Backed up VM's

Post by tsightler »

Didn't I see in another post that you are still on B&R 5.0.2? This script requires a 6.x version of B&R.
flavor4real
Expert
Posts: 205
Liked: 5 times
Joined: Nov 22, 2010 7:57 pm
Full Name: DS
Contact:

Re: Compare vSphere VM's to Backed up VM's

Post by flavor4real »

oh ok,.. I didn't know. Thanks
Post Reply

Who is online

Users browsing this forum: No registered users and 26 guests