PowerShell script exchange
Post Reply
dannordquist
Enthusiast
Posts: 27
Liked: 2 times
Joined: Oct 23, 2014 3:39 pm
Full Name: Dan Nordquist
Contact:

how to translate TargetHostID to the guest server name?

Post by dannordquist »

I'm using powershell to GetLastResult for veeam jobs that have failed or warning status, but the result only gives me a binary hash for the guest server. How do I get the actual name of the server, and if possible, how do I return the failure or warning message with powershell?

Anyone know how to do this?

Thank you,
Dan
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: how to translate TargetHostID to the guest server name?

Post by veremin »

Hi, Dan,

Kindly, try the following script:

Code: Select all

$Job = Get-VBRJob -name "Name of your Job"
$LastSession = $Job.FindLastSession()
$LastSession | Get-VBRTaskSession | ?{$_.status -eq "Failed"} | select name
Thanks.
dannordquist
Enthusiast
Posts: 27
Liked: 2 times
Joined: Oct 23, 2014 3:39 pm
Full Name: Dan Nordquist
Contact:

Re: how to translate TargetHostID to the guest server name?

Post by dannordquist »

Excellent! That's perfect. Thank you.
dannordquist
Enthusiast
Posts: 27
Liked: 2 times
Joined: Oct 23, 2014 3:39 pm
Full Name: Dan Nordquist
Contact:

Re: how to translate TargetHostID to the guest server name?

Post by dannordquist »

Any advice on how to pull the warning/error message text?
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: how to translate TargetHostID to the guest server name?

Post by veremin »

You can get text strings from the latest task session, using the following script. The error message should be there:

Code: Select all

$LastSession.Logger.GetLog().updatedrecords | sort starttime | select title
Thanks.
dannordquist
Enthusiast
Posts: 27
Liked: 2 times
Joined: Oct 23, 2014 3:39 pm
Full Name: Dan Nordquist
Contact:

Re: how to translate TargetHostID to the guest server name?

Post by dannordquist »

That gives me "Job finished with warning at 11/9/2014" but it's the details of the warning I'm looking for
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: how to translate TargetHostID to the guest server name?

Post by veremin »

What about querying Task sessions, then:

Code: Select all

$TaskSession = $LastSession | Get-VBRTaskSession 
$TaskSession.Logger.GetLog().updatedrecords | sort starttime | select title 
Thanks.
dannordquist
Enthusiast
Posts: 27
Liked: 2 times
Joined: Oct 23, 2014 3:39 pm
Full Name: Dan Nordquist
Contact:

Re: how to translate TargetHostID to the guest server name?

Post by dannordquist »

$Job = Get-VBRJob -name "Tier4d-MD-VM1"
$LastSession = $Job.FindLastSession()
$LastSession | Get-VBRTaskSession | ?{$_.status -eq "Warning"} | select name

Name
----
server01


$TaskSession = $LastSession | Get-VBRTaskSession
$TaskSession.Logger.GetLog().updatedrecords | sort starttime | select title
You cannot call a method on a null-valued expression.
At line:1 char:27
+ $TaskSession.Logger.GetLog <<<< ().updatedrecords | sort starttime | select title
+ CategoryInfo : InvalidOperation: (GetLog:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
dannordquist
Enthusiast
Posts: 27
Liked: 2 times
Joined: Oct 23, 2014 3:39 pm
Full Name: Dan Nordquist
Contact:

Re: how to translate TargetHostID to the guest server name?

Post by dannordquist »

Any idea why I'm getting the null error?

Thank you!
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: how to translate TargetHostID to the guest server name?

Post by veremin »

I've just tried the script and everything seems to have worked properly. Does $TaskSession contain something in your case? Can you just input it and see whether it returns something or not? Thanks.
dannordquist
Enthusiast
Posts: 27
Liked: 2 times
Joined: Oct 23, 2014 3:39 pm
Full Name: Dan Nordquist
Contact:

Re: how to translate TargetHostID to the guest server name?

Post by dannordquist »

Yes, when I input $TaskSession it returns a list of all the guest server sessions, but the "$TaskSession.Logger.GetLog().updatedrecords | sort starttime | select title" command still returns the null-value error.
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: how to translate TargetHostID to the guest server name?

Post by veremin »

If $TaskSession contains a list of sessions, try to access just one session that has a problematic VM:

Code: Select all

$TaskSession = $LastSession | Get-VBRTaskSession | where {$_.name -eq "Name of problematic VM"}
$TaskSession.Logger.GetLog().updatedrecords | sort starttime | select title
Thanks.
dannordquist
Enthusiast
Posts: 27
Liked: 2 times
Joined: Oct 23, 2014 3:39 pm
Full Name: Dan Nordquist
Contact:

Re: how to translate TargetHostID to the guest server name?

Post by dannordquist » 1 person likes this post

Ok, yes, thank you. I can work with that. It returns the details for that vm. Thank you very much!
dannordquist
Enthusiast
Posts: 27
Liked: 2 times
Joined: Oct 23, 2014 3:39 pm
Full Name: Dan Nordquist
Contact:

Re: how to translate TargetHostID to the guest server name?

Post by dannordquist »

Hey Vladimir, quick question... I've been searching the documentation and looking through returned data with different commands and I can't find where to discover if the running job is an incremental or a full. Can you help? Thank you.
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: how to translate TargetHostID to the guest server name?

Post by veremin »

The backup session should have a parameter indicating session type. If my memory serves me well, the parameter is called .IsFullMode:

Code: Select all

$LastSession.IsFullMode
Thanks.
dannordquist
Enthusiast
Posts: 27
Liked: 2 times
Joined: Oct 23, 2014 3:39 pm
Full Name: Dan Nordquist
Contact:

Re: how to translate TargetHostID to the guest server name?

Post by dannordquist »

you are THE MAN! Yep, that returns a bool... thank you!
dannordquist
Enthusiast
Posts: 27
Liked: 2 times
Joined: Oct 23, 2014 3:39 pm
Full Name: Dan Nordquist
Contact:

Re: how to translate TargetHostID to the guest server name?

Post by dannordquist »

Another quick question if you don't mind. The veeam jobs sometimes report warnings on the job itself while all the server backups have successfully completed, like this one, "Backup location "E:\Veeam\Backups" is getting low on free disk space (757.3 GB left of 7.3 TB)."

Can you suggest a way to pull the details of that warning?

Also, I am going to post the code I have to share with the forum in a following post. This is so people can use the script you have taught me and improve upon it if they so desire.

Thanks for all your help!
Dan
nefes
Veeam Software
Posts: 649
Liked: 170 times
Joined: Dec 10, 2012 8:44 am
Full Name: Nikita Efes
Contact:

Re: how to translate TargetHostID to the guest server name?

Post by nefes »

Here is the code I use in testing, may require some improvements:

Code: Select all

$session = (Get-VSBSession -Name $jobName | Sort-Object StartTime -Descending)[0] # I use it in SureBackup, use corresponding commandlet to search your type of session
$warnings = $session.Logger.GetLog().UpdatedRecords | ?{$_.Status -eq "EWarning"} | Sort-Object UpdateTime | Select -ExpandProperty Title
$fails = $session.Logger.GetLog().UpdatedRecords | ?{$_.Status -eq "EFailed"} | Sort-Object UpdateTime | Select -ExpandProperty Title
dannordquist
Enthusiast
Posts: 27
Liked: 2 times
Joined: Oct 23, 2014 3:39 pm
Full Name: Dan Nordquist
Contact:

Re: how to translate TargetHostID to the guest server name?

Post by dannordquist »

Thanks nefes, I'll play with that.
dannordquist
Enthusiast
Posts: 27
Liked: 2 times
Joined: Oct 23, 2014 3:39 pm
Full Name: Dan Nordquist
Contact:

Re: how to translate TargetHostID to the guest server name?

Post by dannordquist »

Can't get that script to work, nefes. I'm a C# expert but not a PS expert so I don't know how to fix the errors I'm getting. I sure am learning PS quickly, though! haha

Vladimir, do you have any suggestions for me, to get the job failure when it's not associated with a server, like the disk space warning above?

Thanks!
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: how to translate TargetHostID to the guest server name?

Post by veremin »

Don't those warnings show up, if you query backup sessions, like I've described previously? Thanks.
dannordquist
Enthusiast
Posts: 27
Liked: 2 times
Joined: Oct 23, 2014 3:39 pm
Full Name: Dan Nordquist
Contact:

Re: how to translate TargetHostID to the guest server name?

Post by dannordquist »

I'll see if I can figure it out based on your previous scripts.
dannordquist
Enthusiast
Posts: 27
Liked: 2 times
Joined: Oct 23, 2014 3:39 pm
Full Name: Dan Nordquist
Contact:

Re: how to translate TargetHostID to the guest server name?

Post by dannordquist »

yes, you were right, I just needed to getLog() for the job level result in addition to the task level results

thanks again for your help!
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: how to translate TargetHostID to the guest server name?

Post by veremin »

No worries. Glad to hear that my input has been helpful. Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests