Powershell questions

PowerShell script exchange

Powershell questions

Veeam Logoby ldasilva » Wed Apr 26, 2017 1:54 pm

Hello guys,

I found a power shell script that makes a csv file exporting almost all info. (Job name, Schedule, Repo, Etc,Etc,Etc)

I find it very useful but now i want to add more info in the script to export more data, for example, data size, ESXI Host target, VMs in JOB.

Thank you

Code: Select all
param (
[Parameter(mandatory=$false)] [String]$path


# User Defined Variables

# Open csv file after creation
$autoLaunch = $true

# Static Variables

$scriptName = "Veeam Backup Jobs"
$scriptVer = "3.0"
$scriptDir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
$starttime = Get-Date -uformat "%d-%m-%Y %I:%M:%S"
$allDetails = @()

# Load Snap-ins

# Add Veeam snap-in if required
If ((Get-PSSnapin -Name VeeamPSSnapin -ErrorAction SilentlyContinue) -eq $null) {add-pssnapin VeeamPSSnapin}

# Functions

# Main Procedures

Write-Host "********************************************************************************"
Write-Host "$scriptName`tVer:$scriptVer`t`t`tStart Time:`t$starttime"
Write-Host "********************************************************************************`n"

# Get Backup Jobs
$jobs = Get-VBRJob | ?{$_.JobType -eq "Backup"}

foreach ($job in $jobs) {
$jobOptions = New-Object PSObject
$jobOptions | Add-Member -MemberType NoteProperty -Name "Job Name" -value $job.name
    $jobOptions | Add-Member -MemberType NoteProperty -Name "Backup Type" -value $job.TypeToString
$jobOptions | Add-Member -MemberType NoteProperty -Name "Backup Mode" -value $job.backuptargetoptions.algorithm
    $jobOptions | Add-Member -MemberType NoteProperty -Name "Enabled" -value $job.isscheduleenabled
    $jobOptions | Add-Member -MemberType NoteProperty -Name "Schedule" -value $job.ScheduleOptions.get_NextRun()
    $jobOptions | Add-Member -MemberType NoteProperty -Name "Day" -value $Job.ScheduleOptions.OptionsDaily.kind
    $jobOptions | Add-Member -MemberType NoteProperty -Name "Repository" -value $job.GetTargetRepository().name
    $jobOptions | Add-member -MemberType NoteProperty -name "Repository Path" -value $job.FindTargetRepository().Path
    $jobOptions | Add-member -Membertype NoteProperty -name "Restore Points" -value $job.GetOptions().backupstorageoptions.retainCycles
    $jobOptions | Add-member -MemberType NoteProperty -name "VM in Job" -value $job.GetObjectsInJob().count
    $jobOptions | Add-member -MemberType NoteProperty -name "VM Name" -value $job.GetObjectsInJob().name
$jobsinvm = $null
get-vbrbackup | ?{$_.JobType -eq "Backup"}

foreach ($jobvm in $jobsinvm) {
    $vmobj = $jobvm.GetObjectOibsAll()

    $jobOptions | Add-member -MemberType NoteProperty -name "VM in Job" -value $ObjectNameinj
    foreach ($objectinj in $objectsinj) {
     $BackupNameinj = $backupjob.Name;
     $ObjectNameinj = $objectinj.Name;
     $ObjectCountinj = $objectinj.CountOfValidOibs;
    $bckOptions = New-Object PSObject

#$table | Sort-Object -Property "BackupName" | select BackupName,ObjectName,ObjectCount,ObjectCreationTime

    #$backups = get-vbrbackup

#foreach ($backup in $backups) {
 # foreach ($storage in $backup.getallstorages()) {
  #$allstorages = New-Object psobject
   #$allstorages | Add-Member -MemberType NoteProperty -Name "BackupSizeGB" -value $storage.Info.Stats.BackupSize
   #$allstorages | Add-Member -MemberType NoteProperty -Name "DataSizeGB" -value $storage.Info.Stats.DataSize
    $Objects = $Job | Get-VBRJobObject
    $jobOptions | Add-Member -MemberType NoteProperty -Name "Servers" -value $job.Objects.name
    $proxies = $null
foreach ($prox in ($job | get-vbrjobproxy)) {
$pName = $prox.Name
$proxies = $proxies + $pName
$jobOptions | Add-Member -MemberType NoteProperty -Name "Proxy" -value $proxies
$jobOptions | Add-Member -MemberType NoteProperty -Name "Auto Proxy" -Value $job.sourceproxyautodetect

$allDetails = $jobOptions

# Outputs

# Display results summary
$allDetails | select Name, Enabled | Sort Name | ft -AutoSize

If (!$path -or !$path.EndsWith(".csv")) {
Write-Host "`n`nUsing Default Path"
$path = $scriptDir + "\" + $scriptName + "_" + (Get-Date -uformat %m-%d-%Y_%I-%M-%S) + ".csv"
} Else {
Write-Host "`n`nUsing Supplied Path"

# Export results
$allDetails | Sort Name | Export-Csv $path -NoTypeInformation -Force

# Open csv
If ($autoLaunch) {
Invoke-Item $path

$finishtime = Get-Date -uformat "%d-%m-%Y %I:%M:%S"
Write-Host "`n`n"
Write-Host "********************************************************************************"
Write-Host "$scriptName`t`t`t`tFinish Time:`t$finishtime"
Write-Host "********************************************************************************"

# Prompt to exit script - This leaves PS window open when run via right-click
Write-Host "`n`n"
Write-Host "Press any key to continue ..." -foregroundcolor Gray
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Posts: 5
Liked: never
Joined: Tue Apr 25, 2017 5:43 pm
Full Name: Lisandro da Silva

Return to PowerShell

Who is online

Users browsing this forum: No registered users and 3 guests