Get-VBRReplica

PowerShell script exchange

Get-VBRReplica

Veeam Logoby habibalby » Mon Dec 12, 2011 8:11 am

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,
habibalby
Expert
 
Posts: 350
Liked: 23 times
Joined: Mon Jul 18, 2011 9:30 am
Location: Bahrain
Full Name: Hussain Al Sayed

Re: Get-VBRReplica

Veeam Logoby ThomasMc » Mon Dec 12, 2011 11:16 am

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
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: Get-VBRReplica

Veeam Logoby habibalby » Mon Dec 12, 2011 12:47 pm

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

Thanks,
habibalby
Expert
 
Posts: 350
Liked: 23 times
Joined: Mon Jul 18, 2011 9:30 am
Location: Bahrain
Full Name: Hussain Al Sayed

Re: Get-VBRReplica

Veeam Logoby ThomasMc » Mon Dec 12, 2011 1:16 pm

So does this look like what your after?
Image

or do you want more info included?
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: Get-VBRReplica

Veeam Logoby habibalby » Mon Dec 12, 2011 2:35 pm

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

Thanks,
habibalby
Expert
 
Posts: 350
Liked: 23 times
Joined: Mon Jul 18, 2011 9:30 am
Location: Bahrain
Full Name: Hussain Al Sayed

Re: Get-VBRReplica

Veeam Logoby ThomasMc » Mon Dec 12, 2011 2:42 pm

I've updated the image, anything else?
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: Get-VBRReplica

Veeam Logoby habibalby » Mon Dec 12, 2011 2:51 pm

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

Thanks,
habibalby
Expert
 
Posts: 350
Liked: 23 times
Joined: Mon Jul 18, 2011 9:30 am
Location: Bahrain
Full Name: Hussain Al Sayed

Re: Get-VBRReplica

Veeam Logoby ThomasMc » Mon Dec 12, 2011 4:09 pm

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: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: Get-VBRReplica

Veeam Logoby ThomasMc » Mon Dec 12, 2011 6:28 pm

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
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: Get-VBRReplica

Veeam Logoby habibalby » Mon Dec 12, 2011 7:02 pm

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

Thanks,
S.Hussain
habibalby
Expert
 
Posts: 350
Liked: 23 times
Joined: Mon Jul 18, 2011 9:30 am
Location: Bahrain
Full Name: Hussain Al Sayed

Re: Get-VBRReplica

Veeam Logoby ThomasMc » Mon Dec 12, 2011 7:22 pm

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
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: Get-VBRReplica

Veeam Logoby habibalby » Mon Dec 12, 2011 7:36 pm

Hi,
Any file CSV or HTML will work.
habibalby
Expert
 
Posts: 350
Liked: 23 times
Joined: Mon Jul 18, 2011 9:30 am
Location: Bahrain
Full Name: Hussain Al Sayed

Re: Get-VBRReplica

Veeam Logoby ThomasMc » Tue Dec 13, 2011 10:19 am

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
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: Get-VBRReplica

Veeam Logoby habibalby » Tue Dec 13, 2011 12:47 pm

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

Thanks,
habibalby
Expert
 
Posts: 350
Liked: 23 times
Joined: Mon Jul 18, 2011 9:30 am
Location: Bahrain
Full Name: Hussain Al Sayed

Re: Get-VBRReplica

Veeam Logoby ThomasMc » Tue Dec 13, 2011 12:52 pm

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
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Next

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 4 guests