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 » Nov 10, 2014 3:35 pm

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: 17017
Liked: 1462 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 » Nov 10, 2014 3:47 pm

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 » Nov 10, 2014 5:03 pm

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 » Nov 10, 2014 5:05 pm

Any advice on how to pull the warning/error message text?

veremin
Product Manager
Posts: 17017
Liked: 1462 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 » Nov 10, 2014 5:09 pm

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 » Nov 10, 2014 5:14 pm

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: 17017
Liked: 1462 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 » Nov 10, 2014 5:27 pm

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 » Nov 10, 2014 6:44 pm

$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 » Nov 10, 2014 9:50 pm

Any idea why I'm getting the null error?

Thank you!

veremin
Product Manager
Posts: 17017
Liked: 1462 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 » Nov 11, 2014 9:08 am

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 » Nov 11, 2014 12:41 pm

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: 17017
Liked: 1462 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 » Nov 11, 2014 12:51 pm

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 » Nov 11, 2014 12:58 pm 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 » Nov 12, 2014 7:01 pm

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: 17017
Liked: 1462 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 » Nov 13, 2014 7:12 am

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 » Nov 13, 2014 12:51 pm

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 » Nov 19, 2014 2:12 pm

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: 631
Liked: 157 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 » Nov 19, 2014 2:19 pm

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 » Nov 19, 2014 2:32 pm

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 » Nov 20, 2014 1:01 pm

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: 17017
Liked: 1462 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 » Nov 20, 2014 1:09 pm

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 » Nov 20, 2014 1:20 pm

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 » Nov 26, 2014 4:02 pm

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: 17017
Liked: 1462 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 » Nov 26, 2014 7:45 pm

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 7 guests