2020 | Scott W. Head  |  Sr. Systems Admin | Certified Microsoft Windows Server Administrator

PowerShell Veeam Module

Veeam is a powerful backup software solution for physical and virtual environments. I did not like the interface of Veeam due to the lack of history reporting on backups and job membership history. I created a SQL database and website to display the jobs and job membership, this was because I was in charge of backups but not the only one with rights to the Veeam software. I could easily review changes to jobs in my website I developed. Anyhow, here is the script I used to pull some information from the Veeam server.

Veeam PowerShell Installation

Veeam Explorers PowerShell Reference

        
        #Load Veeam Snapin and ran from Veeam server
        add-pssnapin VeeamPssnapin
        
       
#Connects to VMware vCenter Server
        Connect-VIServer  -Server YourvCenterServerHere
        
   
    #Connencts to SQL Server
        $conn = New-Object System.Data.SqlClient.SqlConnection("Data Source=SQLServerName; Initial Catalog=SQLDBName; User ID=sa; Password=YourPassword")
        $conn.Open()
        $cmd = $conn.CreateCommand()
        
        $Dates= Get-Date
        $Dates=$Dates.ToShortDateString()
        
   
    #Runs a Veeam cmdlet to get jobs 
        foreach($job in Get-VBRJob)
        {
        
        $MyJobName=$job.Name
        
        $MoreVM=$job.GetObjectsInJob()
        
        foreach($VM in $MoreVM)
        {
        $VMNames=$VM.Name
        
       
#SQL Insert Statement of Veeam jobs and servers on jobs and current date
        Try{
        
            $cmd.CommandText ="INSERT INTO [DOCUMENT].[dbo].[VeeamJobs]([JobName], [ServerName], [Date]) VALUES ('$MyJobName', '$VMNames','$Dates')"
            $cmd.ExecuteNonQuery()
            $cmd.CommandText  | Out-file C:\temp\JobLog-SQL-Write-Statement_Log.txt -Append
        }Catch [Exception]{
            $_.Exception.Message | Out-file C:\temp\JobError-SQL-Write-Error.txt -Append
            $cmd.CommandText  | Out-file C:\temp\JobLog-SQL-Write-Statement_Log.txt -Append
        } 
        }
        }