PowerShell script exchange
Post Reply
Posts: 106
Liked: 13 times
Joined: Jul 26, 2018 8:04 pm
Full Name: Eugene V

When not found with Find-VBRViEntity?

Post by evilaedmin » Oct 10, 2019 3:58 pm


What's the best way to detect if Find-VBRViEntity returned no results?

Code: Select all

$Result = Find-VBRViEntity -Name "VMthatdoesnotexit"
if (!$Result) { 
	//Do Some kind of counting here

Veeam Software
Posts: 7
Liked: 3 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov

Re: When not found with Find-VBRViEntity?

Post by oleg.feoktistov » Oct 10, 2019 5:08 pm 3 people like this post

Hi Eugene,

By default, If the entity with the name you specified for Find-VBRViEntity cmdlet doesn't exist, powershell will just resolve an empty line.
If you want to configure some kind of message notifying you on the entity absence, I would suggest to use "throw" keyword in your if statement.
In this case, it will resolve a system-like error with a custom text you wrote.

Code: Select all

$ViEntityName = "VMDoesnotexist"
$Result = Find-VBRViEntity -Name $ViEntityName
if (!$Result) {
    throw "Entity with the name $ViEntityName is not found"
else {
All the best,

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest