PowerShell script exchange
Post Reply
wgoodall
Enthusiast
Posts: 28
Liked: never
Joined: Aug 30, 2022 6:21 am
Full Name: Wesley Goodall
Contact:

Get-VBRViEntity : The term 'Get-VBRViEntity'

Post by wgoodall »

Veeam v11

Hi All,

Getting this error with a Veeam script can anyone help?

Is this to do with the module not loading?

Code: Select all

Get-VBRViEntity : The term 'Get-VBRViEntity' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again
Thanks for any help you can give.
jorgedlcruz
Veeam Software
Posts: 1372
Liked: 619 times
Joined: Jul 17, 2015 6:54 pm
Full Name: Jorge de la Cruz
Contact:

Re: Get-VBRViEntity : The term 'Get-VBRViEntity'

Post by jorgedlcruz »

Hello,
Have you tried to open it like this (From the backup server - menu - console - PowerShell)? Then give it a try and see if it all works there. If it does, and you are trying this script from your own PC, you will need to have the VeeamPSSnapin on your computer as well. Let us know
Jorge de la Cruz
Senior Product Manager | Veeam ONE @ Veeam Software

@jorgedlcruz
https://www.jorgedelacruz.es / https://jorgedelacruz.uk
vExpert 2014-2024 / InfluxAce / Grafana Champion
wgoodall
Enthusiast
Posts: 28
Liked: never
Joined: Aug 30, 2022 6:21 am
Full Name: Wesley Goodall
Contact:

Re: Get-VBRViEntity : The term 'Get-VBRViEntity'

Post by wgoodall »

Hi I'm calling this function from a script on the Veeam server and I do have a line to load the snapin.. this is on a v11 server

Sample below

Code: Select all

# Loads Veeam Powershell Snapin
Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue

# Set the location to the current working directory
Set-location "C:\temp"

# Define the path to the output CSV file
$csvFilePath = "C:\VeeamBackupReport.csv"

# Define an empty array to store the results
$results = @()

# Loop through all Veeam backup jobs
Get-VBRJob | ForEach-Object {
    $jobName = $_.Name
    
    # Loop through all VMs included in the job
    $vmList = Get-VBRViEntity -Job $_ | Where-Object {$_.ObjectType -eq "VM"}
    foreach ($vm in $vmList) {
        try {
            # Get the guest OS type of the VM
            $guestOSType = $vm.GuestOSType.Name
            
            # Check if the guest OS type is supported
            $supportedGuestOS = @("Windows", "Linux")
            if ($supportedGuestOS -notcontains $guestOSType) {
                # If the guest OS type is not supported, add a failure result to the array and continue to the next VM
                $results += New-Object PSObject -Property @{
                    JobName = $jobName
                    VMName = $vm.Name
                    GuestOSType = $guestOSType
                    Result = "Failure: Guest OS not supported"
                }
                continue
            }
david.domask
Veeam Software
Posts: 1226
Liked: 322 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Get-VBRViEntity : The term 'Get-VBRViEntity'

Post by david.domask »

Hi @wgoodall

https://helpcenter.veeam.com/docs/backu ... ml?ver=120

It's Find-VBRViEntity, not Get :)
David Domask | Product Management: Principal Analyst
wgoodall
Enthusiast
Posts: 28
Liked: never
Joined: Aug 30, 2022 6:21 am
Full Name: Wesley Goodall
Contact:

Re: Get-VBRViEntity : The term 'Get-VBRViEntity'

Post by wgoodall »

Thanks let me try that .. i hope it's that simple :)
wgoodall
Enthusiast
Posts: 28
Liked: never
Joined: Aug 30, 2022 6:21 am
Full Name: Wesley Goodall
Contact:

Re: Get-VBRViEntity : The term 'Get-VBRViEntity'

Post by wgoodall »

Hi David

Thanks that really helped and is defiantly the right command now :0)

but I think I'm targeting the wrong parameter

Can you take a look at the sample below, I've also put the output of the CSV that is used.

Code: Select all

# Loads Veeam Powershell Snapin
Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue

# Set the location to the current working directory
Set-location "C:\temp"

# Get all VBR Jobs and write the job name and its objects to a CSV file
Get-VBRJob | % {
  $job = $_
  Write-Host "Job:", $job.Name
  $job.GetObjectsInJob() | select @{n='Job';e={$job.Name}}, Name
} | Export-Csv 'target.csv' -NoTypeInformation



# Targeted File or Folder
$originalFiles = "C:\windows\web"

# Import the CSV file
$VMs = Import-Csv -Path "target.csv"

# Create an empty array to store the results of each restore attempt

# Loop through all Veeam backup jobs
Get-VBRJob | ForEach-Object {
   $jobName = $_.Name

      
    # Loop through all VMs included in the job
    $vmList = Find-VBRViEntity -Job $_ | Where-Object {$_.ObjectType -eq "VM"}
    foreach ($vm in $vmList) {
        try {
            # Get the guest OS type of the VM
            $guestOSType = $vm.GuestOSType.Name
            
            # Check if the guest OS type is supported
            $supportedGuestOS = @("Windows", "Linux")
            if ($supportedGuestOS -notcontains $guestOSType) {
                # If the guest OS type is not supported, add a failure result to the array and continue to the next VM
                $results += New-Object PSObject -Property @{
                    JobName = $jobName
                    VMName = $vm.Name
                    GuestOSType = $guestOSType
                    Result = "Failure: Guest OS not supported"
                }
                continue
            }
            
            # If the guest OS type is supported, add a success result to the array
            $results += New-Object PSObject -Property @{
                JobName = $jobName
                VMName = $vm.Name
                GuestOSType = $guestOSType
                Result = "Success"
            }
        } catch {
            # If an error occurred while retrieving the guest OS type, add a failure result to the array
            $results += New-Object PSObject -Property @{
                JobName = $jobName
                VMName = $vm.Name
                GuestOSType = ""
                Result = "Failure: Unable to retrieve guest OS"
            }
        } 

CSV

Code: Select all

Job	Name
FELIX-VEEAM	FELIX-VEEAM
FELIX-DC	FELIX-DC

Thanks for all your help
david.domask
Veeam Software
Posts: 1226
Liked: 322 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Get-VBRViEntity : The term 'Get-VBRViEntity'

Post by david.domask »

Hiya @wgoodall, glad that part was simple enough :)

Can you explain a bit what you're trying to check? I understand your code well enough, but just want to make sure I understand what you want in your reports.

The output you have looks like it got your first loop fine, so I'm guessing it's the 2nd isn't working, but I just want to ensure I get what you're aiming for.
David Domask | Product Management: Principal Analyst
wgoodall
Enthusiast
Posts: 28
Liked: never
Joined: Aug 30, 2022 6:21 am
Full Name: Wesley Goodall
Contact:

Re: Get-VBRViEntity : The term 'Get-VBRViEntity'

Post by wgoodall »

Hi David

So I'm wanting to check the guest O/S of the back up , and skip non supported backups , have it recorded in the report and continue.

But now as I write this I'm realizing the initial generated CVS may not contain that information.

In your opinion what do I need to add to make that check?

Thanks for all your help
david.domask
Veeam Software
Posts: 1226
Liked: 322 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Get-VBRViEntity : The term 'Get-VBRViEntity'

Post by david.domask »

Hi @wgoodall,

So just to make sure I get it right, the goal is to check for any non-Windows and non-Linux VMs being backed up? Is that correct?

I think you might want to go with the following:

1. Get all Jobs and save to some variable $jobs ( $jobs = Get-VBRJob )
2. Foreach Job, loop over it and
2a. Save the job objects to $JobObjects = Get-VBRJobObject -Job $job
2b. Each CJobObject has a GetObject() method, and we can use the GuestInfo property to get GuestInfo.

So something like:

Code: Select all

$jobs = Get-VBRJob
$jobObjects = @()
Foreach($j in $jobs){
     $loopObjects = $j.GetObjectsinJob()
     Foreach($lo in $loopObjects){
		 $ObjectJobData = [PSCUstomObject]@{
		 JobName = $j.Name
		 JobObject = $lo.name
		 ObjectGuestOSType = $lo.GetObject().GuestInfo.GetOsType()
		}	
     $jobObjects += $ObjectJobData
     }
}
PS C:\Users\Administrator> $jobObjects

JobName              JobObject                        ObjectGuestOSType
-------              ---------                        -----------------
old-vbr              ddom-veeam-rb3-buch         windows2019srv_64Guest
restore-test         C:\ProgramData\Veeam\Backup             otherGuest
vmware-ffi-cap-bb    ddom-tinyvm                 windows2019srv_64Guest
vmware-per-job       ddom-tinyvm                 windows2019srv_64Guest
vmware-per-job       DDom-TinyVM_replica          windows8Server64Guest
vmware-direct-objstg ddom-tinyvm                 windows2019srv_64Guest
vmware-direct-objstg ddom-tinyvm_replica         windows2019srv_64Guest
vmware-direct-objstg DDom-TinyVM_replica          windows8Server64Guest
quick-rep            ddom-tinyvm                 windows2019srv_64Guest
quick-rep            ddom-tinyvm_replica         windows2019srv_64Guest
convert-test         ddom-tinyvm                 windows2019srv_64Guest
convert-test         ddom-tinyvm_replica         windows2019srv_64Guest
simple-replica       ddom-tinyvm                 windows2019srv_64Guest
simple-replica       ddom-debian-backmeup              debian10_64Guest
And then I would just filter on anything that returns otherGuest and look for any "unique" backups in your environment. (if it were me and I had a standard linux distribution, I would check where the ObjectGuestOSType is not like windows* or the various linux flavors that I know are in my environment).

Does this help?

Edit: Also, if you want those names to be "friendlier", you can just write a function that converts the expected output and checks for windows* or your various linux flavors you use and just change that property on the PSCustomObject to Windows or Linux respectively.

This might make your checking easier and will also show you when someone deploys an unexpected distro ;) Perfect for wrist slapping if you have regulations on what to be deployed :).
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests