PowerShell script exchange
Post Reply
habibalby
Expert
Posts: 379
Liked: 24 times
Joined: Jul 18, 2011 9:30 am
Full Name: Hussain Al Sayed
Location: Bahrain
Contact:

Get-VBRReplica

Post by habibalby »

Hi,
Any script to list the Replica Jobs in detailed, such as job, type, name, status, result, target, target LUN Size / "optional" free size on target LUN?

Thanks,

ThomasMc
Expert
Posts: 293
Liked: 18 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Get-VBRReplica

Post by ThomasMc »

You could probably pull all that info out of the Get-VBRBackupSession

Code: Select all

$session = Get-VBRBackupSession -Name "Replication Job" | Sort CreationTime -Descending | Select -First 1

$session | fl
$session.Progress
$session.BackupStats | fl
As for your Lun info

Code: Select all

Get-VBRServer -Name "ESXiServer" | Find-VBRDatastore | fl

habibalby
Expert
Posts: 379
Liked: 24 times
Joined: Jul 18, 2011 9:30 am
Full Name: Hussain Al Sayed
Location: Bahrain
Contact:

Re: Get-VBRReplica

Post by habibalby »

Hello,
Can't be by the job Type followed by other information I required?

Thanks,

ThomasMc
Expert
Posts: 293
Liked: 18 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Get-VBRReplica

Post by ThomasMc »

So does this look like what your after?
Image

or do you want more info included?

habibalby
Expert
Posts: 379
Liked: 24 times
Joined: Jul 18, 2011 9:30 am
Full Name: Hussain Al Sayed
Location: Bahrain
Contact:

Re: Get-VBRReplica

Post by habibalby »

Hello,
This is fantastic, is it possible to bring in the LUN Name target?

Thanks,

ThomasMc
Expert
Posts: 293
Liked: 18 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Get-VBRReplica

Post by ThomasMc »

I've updated the image, anything else?

habibalby
Expert
Posts: 379
Liked: 24 times
Joined: Jul 18, 2011 9:30 am
Full Name: Hussain Al Sayed
Location: Bahrain
Contact:

Re: Get-VBRReplica

Post by habibalby »

That's great, can I get the syntax please?

Thanks,

ThomasMc
Expert
Posts: 293
Liked: 18 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Get-VBRReplica

Post by ThomasMc »

This should be you

Code: Select all

function Get-vPCReplicaStuff {
	param (
		[Parameter(Position=0,
		ValueFromPipeline=$true,
		ValueFromPipelineByPropertyName=$true)]
		[Alias("Name")]
		[String]$jobName
		)
	PROCESS {
		$job = Get-VBRJob -Name $jobName
		$str = Get-VBRReplica -Name $job.Name
		$esxi = Get-VBRServer | ?{$_.Id -eq $job.TargetHostId}
		$dtstr =  $esxi | Find-VBRDatastore -Name $job.ViReplicaTargetOptions.DatastoreName

		$hashy = @{"Job Name" = "$($job.Name)"; "Target Type" = "$($job.TargetType)"; "Replica Name" = "$($str.Name)";
		"State" = "$($job.GetLastState())"; "Last Result" = "$($job.GetLastResult())"; "Target Name" = "$($esxi.Name)";
		"Storage Info (Free/Total)" = "$($dtstr.FreeSpace / 1GB) / $($dtstr.Capacity / 1GB)"}

		$output = New-Object -TypeName PSObject -Property $hashy
	}
	End {
	$output
	}
}
Usage

Code: Select all

Get-VBRJob | ?{$_.IsReplica} | Get-vPCReplicaStuff
Output

Code: Select all

Storage Info (Free/Total) : 897.0234375 / 931.25
Last Result               : Success
Target Type               : SnapReplica
Replica Name              : VC Replication
Target Name               : esxi03
Job Name                  : VC Replication
State                     : Stopped

ThomasMc
Expert
Posts: 293
Liked: 18 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Get-VBRReplica

Post by ThomasMc »

Forgot the Datastore, rounded the storage figures and change some of the names for easier access

Code: Select all


function Get-vPCReplicaStuff {
   param (
      [Parameter(Position=0,
      ValueFromPipeline=$true,
      ValueFromPipelineByPropertyName=$true)]
      [Alias("Name")]
      [String]$jobName
      )
   PROCESS {
      $job = Get-VBRJob -Name $jobName
      $str = Get-VBRReplica -Name $job.Name
      $esxi = Get-VBRServer | ?{$_.Id -eq $job.TargetHostId}
      $dtstr =  $esxi | Find-VBRDatastore -Name $job.ViReplicaTargetOptions.DatastoreName

      $hashy = @{"Job" = "$($job.Name)"; "Type" = "$($job.TargetType)"; "Name" = "$($str.Name)";
      "State" = "$($job.GetLastState())"; "Result" = "$($job.GetLastResult())"; "Target" = "$($esxi.Name)";
      "Datastore" = "$($job.ViReplicaTargetOptions.DatastoreName)"; 
      "StorageInfo" = "$('{0:N2}' -f $($dtstr.FreeSpace / 1GB))GB/$('{0:N2}' -f $($dtstr.Capacity / 1GB))GB"}

      $output = New-Object -TypeName PSObject -Property $hashy
   }
   End {
   $output
   }
}
Output

Code: Select all

State       : Stopped
StorageInfo : 890.98GB/931.25GB
Name        : VC Replication
Type        : SnapReplica
Job         : VC Replication
Target      : esxi03
Result      : Success
Datastore   : LCL-DATASTORE
Usage hasn't changed

habibalby
Expert
Posts: 379
Liked: 24 times
Joined: Jul 18, 2011 9:30 am
Full Name: Hussain Al Sayed
Location: Bahrain
Contact:

Re: Get-VBRReplica

Post by habibalby »

Hi,
I saved it as ps1 script but it doesn't run.

Thanks,
S.Hussain

ThomasMc
Expert
Posts: 293
Liked: 18 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Get-VBRReplica

Post by ThomasMc »

habibalby wrote:Hi,
I saved it as ps1 script but it doesn't run.

Thanks,
S.Hussain
That won't work as the ps1 file won't be loading the Veeam snapin or calling the function, to make it easy let me know what sort of file(CSV/HTML) you want and I'll finish it off for you

habibalby
Expert
Posts: 379
Liked: 24 times
Joined: Jul 18, 2011 9:30 am
Full Name: Hussain Al Sayed
Location: Bahrain
Contact:

Re: Get-VBRReplica

Post by habibalby »

Hi,
Any file CSV or HTML will work.

ThomasMc
Expert
Posts: 293
Liked: 18 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Get-VBRReplica

Post by ThomasMc »

Try this out( edit '$file = "C:\Scripts\Test.htm"' to the correct location and filename you would like)

Code: Select all

######### Edit Path and File Name#################
$file = "C:\Scripts\Test.htm"
##################################################

$html = "<style>"
$html = $html + "BODY{background-color:#fff;}"
$html = $html + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$html = $html + "TH{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:#00FF00}"
$html = $html + "TD{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:#fff}"
$html = $html + "</style>"

########## Don't Touch ###########################
asnp "VeeamPSSnapIn" -ErrorAction SilentlyContinue

function Get-vPCReplicaStuff {
   param (
      [Parameter(Position=0,
      ValueFromPipeline=$true,
      ValueFromPipelineByPropertyName=$true)]
      [Alias("Name")]
      [String]$jobName
      )
   PROCESS {
      $job = Get-VBRJob -Name $jobName
      $str = Get-VBRReplica -Name $job.Name
      $esxi = Get-VBRServer | ?{$_.Id -eq $job.TargetHostId}
      $dtstr =  $esxi | Find-VBRDatastore -Name $job.ViReplicaTargetOptions.DatastoreName

      $hashy = @{"Job" = "$($job.Name)"; "Type" = "$($job.TargetType)"; "Name" = "$($str.Name)";
      "State" = "$($job.GetLastState())"; "Result" = "$($job.GetLastResult())"; "Target" = "$($esxi.Name)";
      "Datastore" = "$($job.ViReplicaTargetOptions.DatastoreName)"; 
      "StorageInfo" = "$('{0:N2}' -f $($dtstr.FreeSpace / 1GB))GB/$('{0:N2}' -f $($dtstr.Capacity / 1GB))GB"}

      $output = New-Object -TypeName PSObject -Property $hashy
   }
   End {
   $output
   }
}

Get-VBRJob | ?{$_.IsReplica} | %{Get-vPCReplicaStuff $_.Name} | 
Select Job, Type, Name, State, Result, Target, Datastore, Storageinfo | 
ConvertTo-HTML -head $html | Out-File $file

Invoke-Expression $file

habibalby
Expert
Posts: 379
Liked: 24 times
Joined: Jul 18, 2011 9:30 am
Full Name: Hussain Al Sayed
Location: Bahrain
Contact:

Re: Get-VBRReplica

Post by habibalby »

Hello,
Thank you, I run it it runs fine without any issue. But when I open the Test.htm nothing appears.

Thanks,

ThomasMc
Expert
Posts: 293
Liked: 18 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Get-VBRReplica

Post by ThomasMc »

Are you on v5 or v6 Veeam b&r? And your saving it and running it on the Veeam server? seems to work fine on mine

habibalby
Expert
Posts: 379
Liked: 24 times
Joined: Jul 18, 2011 9:30 am
Full Name: Hussain Al Sayed
Location: Bahrain
Contact:

Re: Get-VBRReplica

Post by habibalby »

Hello,
I'm on version 5, and yes i'm saving it on veeam machine and C:\Scripts folder on veeam machine as well.

ThomasMc
Expert
Posts: 293
Liked: 18 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Get-VBRReplica

Post by ThomasMc »

well I can't help you there, sorry, this uses the v6 parameters and new cmdlets and I don't run v5 to rewrite it for that

Gostev
SVP, Product Management
Posts: 26706
Liked: 4277 times
Joined: Jan 01, 2006 1:01 am
Location: Baar, Switzerland
Contact:

Re: Get-VBRReplica

Post by Gostev »

Yes another good reason to upgrade!

habibalby
Expert
Posts: 379
Liked: 24 times
Joined: Jul 18, 2011 9:30 am
Full Name: Hussain Al Sayed
Location: Bahrain
Contact:

Re: Get-VBRReplica

Post by habibalby »

will plan that... Thanks a lot for your great help.. Highly appreciated.

Post Reply

Who is online

Users browsing this forum: divyesh and 4 guests