Veeam: Change Restore points and deleted VMs retention period


If you want to change the amount of restore points and the deleted VMs retention period, you can do this for your backup jobs by hand. But if you need to change a lot of Veeam Backup & Replication Jobs like I needed to do. You can find these settings in the Backup Job properties:

image

If you’re a reader of my blog, you know I like to automate this kind of jobs with Powershell. So I created a function to perform this change for me.

The function:

#requires -pssnapin VeeamPSSnapIn
Function Change-RestorePoints{
<#
.SYNOPSIS
    Change the Backup restore points and deleted VMs retention period
.DESCRIPTION

.NOTES
    Authors: Arne Fokkema
.PARAMETER JobName
    A Backup Job in Veeam Backup & Replication
.PARAMETER RetainDays
    The amount of restore points
.PARAMETER RetainCycles
    The amount of days for Deleted VMs retention period    
.EXAMPLE
    PS> Change-RestorePoints -JobName "Job-01" -RetainDays "21" -RetainCycles "21"
#>
    param(
        [parameter(valuefrompipeline = $true,
            position = 0,
            Mandatory = $true,
            HelpMessage = "Enter a Veeam B&R JobName")]
            $JobName,
        [parameter(valuefrompipeline = $true,
            position = 0,
            Mandatory = $true,
            HelpMessage = "Enter the amount of restore points to keep on disk")]
            $RetainDays,
        [parameter(valuefrompipeline = $true,
            position = 0,
            Mandatory = $true,
            HelpMessage = "Enter a deleted VMs retention period in days")]
            $RetainCycles
    )

    begin{
        $vbrjob = Get-VBRJob  | where {$_.Name -eq $JobName} 
    }
    
    process{
        $options = $vbrjob.GetOptions()
        $options.RetainDays = $RetainDays
        $options.RetainCycles = $RetainCycles
        Write-Host "Changing RetainDays: $($RetainDays) and RetainDays: $($RetainCycles) for job: $($vbrjob.Name)"
        $vbrjob.SetOptions($options)
    }
}

To change a particular job on a Veeam Backup & Replication server you can use the following one-liner:

Change-RestorePoints -JobName "Job-01" -RetainDays "30" -RetainCycles "30"

To change all the jobs on a particular Veeam Backup & Replication Server you can use the following foreach loop:

foreach($job in (Get-VBRJob | Sort Name)){
    Change-RestorePoints -JobName $job.Name -RetainDays "14" -RetainCycles "14"
}

The output will look like this:

image

Advertisement

Veeam: How to change the Job notification settings with Powershell


Today just a quick post about how Powershell can help you change the VM attribute option in Veeam Backup & Replication. Imaging that you have 20 backup jobs and you want or need to change the VM attribute settings. You can do this for every job with 10 mouse clicks or you can do it in five seconds by running the script from this post.

This is the setting I am talking about from the GUI:

image

When you change the “Notes” value to some custom field in you environment, the script will apply this setting for you.

if((Get-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue) -eq $null){
    Add-PSSnapin "VeeamPSSnapIn"
}

$vbrserver = Get-VBRServer | Where {$_.Type -eq "VC"}
Foreach($vbrjob in (Get-VBRJob)){    
    $options = $vbrjob.GetOptions()
    $options.VmAttributeName = "Notes"
    $options.SetResultsToVmNotes = $true
    $vbrjob.SetOptions($options)
}

The first three lines of code checked if the VeeamPSSnapIn is loaded, if this is not the case it will be loaded via the Add-PSSnapin.

  • The backup options will be loaded via the .GetOptions() method.
  • VmAttibuteName is the value which you normally enter in the attribute field.
  • SetResultsToVmNotes is the checkbox to enable this setting.
  • via .SetOptions() method you can apply the new settings.

Veeam: Change the Veeam Storage Optimization with Powershell


In Veeam Backup and Replication you can choose three different types of Storage optimization.

image

See the blog post on the Veeam website for more info: http://www.veeam.com/blog

From @gostev I received the following tip:

Note that storage optimization will not take effect until next full backup. Setting is used for newly created backup storage only.

There is no standard cmdlet to change this settings, so we have to find the property of the Storage optimization settings. With some trial and error I found the stgBlockSize property. This property can be found inside the vbrjob options.

You can view this properties via:

$vbrjob = Get-VBRJob | where {$_.Name -eq "<vbrjobname>"}
$options = $vbrjob.GetOptions()

and via the StgBlockSize property you are able to find the actual value of this setting.

$options.StgBlockSize

I have tried the three options from the screenshot and found the following three values:

    $localtarget = "KbBlockSize1024"
    $lantarget = "KbBlockSize512"
    $wantarget = "KbBlockSize256"

Now we have found the properties we need to change the settings via PowerShell. We can build some scripts.

If you want to change the Storage option to LAN target on all your backup jobs. You can run the following script on your Veeam Backup and Replication server. Don’t forget to change the StgBlockSize value with the variable you want to use.

if((Get-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue) -eq $null){
    Add-PSSnapin "VeeamPSSnapIn"
}

$vbrjobs = Get-VBRJob 

foreach($vbrjob in $vbrjobs){

    #Storage optimization 
    $localtarget = "KbBlockSize1024"
    $lantarget = "KbBlockSize512"
    $wantarget = "KbBlockSize256"

    #Change Job Options
    $options = $vbrjob.GetOptions()
    $options.StgBlockSize = $lantarget

    $vbrjob.SetOptions($options)
}

Or if you want to change just a couple of your jobs, you can use the following script:

if((Get-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue) -eq $null){
    Add-PSSnapin "VeeamPSSnapIn"
}

$vbrjobs = "<Job1>","<Job2>"

foreach($vbrjobname in $vbrjobs){

    #Storage optimization 
    $localtarget = "KbBlockSize1024"
    $lantarget = "KbBlockSize512"
    $wantarget = "KbBlockSize256"

    #Change Job Options
    $vbrjob = Get-VBRJob  | where {$_.Name -eq $vbrjobname} 
    $options = $vbrjob.GetOptions()
    $options.StgBlockSize = $lantarget

    $vbrjob.SetOptions($options)
}

So with the Powershell toolkit for Veeam you can perform every change you want and can do via the GUI. You can expect some more posts about automating Veeam Backup and Replication with Powershell.

PowerCLI: Host Networking Device info


In this post I will share a simple PowerCLI script which generates some Network Device information from your vSphere hosts. The information you’ll get is the vmHost name, device name, linkspeed and MAC address.

$vmHostNicInfo = @()
foreach($vmHost in (Get-VMHost | Sort Name)){
    foreach($nic in $vmhost.NetworkInfo.PhysicalNic){ 
        $Details = "" | Select vmHost, Device,Linkspeed,Mac

        $Details.vmHost = $vmhost.Name
        $Details.Device = $nic.Extensiondata.Device
        $Details.Linkspeed = ($nic.Extensiondata.Linkspeed).SpeedMB
        $Details.Mac = $nic.Extensiondata.Mac
    
        $vmHostNicInfo += $Details
    }
}
$vmHostNicInfo | Format-Table -AutoSize

The output will look like this:image

But what if you only want to see the devices with a link speed lower then 1000? Well that’s possible with the following end line:

$vmHostNicInfo | Where {$_.Linkspeed -lt "1000"} |  Format-Table -AutoSize

image

Or if you want to know which device/host belongs to a particular MAC address. You can use the following end line:

$vmHostNicInfo | Where {$_.Mac -eq "00:07:e9:1f:f9:bf"} |  Format-Table -AutoSize

image

So with a small script, you’re able to export valuable data.

PowerCLI: VMware Tools one-liners


In this post I’ll show you three PowerCLI one-liners to perform some operations with VMware Tools.

The first one-liner will return all Powered on VM’s with Windows selected as guest OS and perform a VMware Tools upgrade without a reboot at the end.

Get-VM | Where {$_.PowerState -eq "PoweredOn" -and $_.Guest.OSFullName -match "Win*"} | % {Update-Tools -VM $_ -NoReboot}

Sometimes if you want to perform a vMotion or when you try set a host in maintenance mode, the VM won’t vMotion away from the host. Most of the time this is caused by a mounted ISO from a locale datastore. In my environment this is not possible because I use a shared storage datastore to storage all the ISO files. But there is one ISO that’s mounted from a locale datastore, this is the VMware Tools ISO.  Sometimes the ISO isn’t automatically dismounted from the VM. This one-liner creates a list of VM’s where the VMware Tools ISO is mounted:

(Get-VM | Get-View | Where {$_.Runtime.ToolsInstallerMounted}) | % {$_.Name}

The last one-liner will dismount the VMware Tools if necessary:

(Get-VM | Get-View | Where {$_.Runtime.ToolsInstallerMounted}) | % {Dismount-Tools -VM $_.Name}

I think there will be a lot more possibilities to script with PowerCLI and VMware Tools. So if you have a question or an idea, please leave a comment below.

vCenter Update Manager PowerCLI: Error 1722 Windows Installer


Today I was building a new Windows 7 View Desktop in my home lab. PowerCLI and vCenter Update Manager cmdlets where of course the first things I wanted to install. But during the setup of vCenter Update Manager PowerCLI I received the following error:

image

I was trying to install VMware-UpdateManager-Pscli-4.0.0-233997.exe after downloading the new version: VMware-UpdateManager-Pscli-4.1.0-266648.exe I was able to install the vCenter Update Manager cmdlets again. So if you’re running Windows 7 and want to use the vCenter Update Manager PowerCLI cmdlets, just install the latest version and you don’t get the this error.

 

Source http://communities.vmware.com/thread/257870

PowerCLI: Update-VMHost Function


Since the release of the vCenter Update Manager PowerCLI cmdlets back in march last year. I was hoping to find some time to play with it. Now this weekend I had some spare time to finally play with these new cmdlets. So I downloaded the setup file from http://communities.vmware.com and installed it on my PC. Then I started to Google and searched for existing scripts. I a couple of good posts. One by @alanrenouf with a short introduction video and a post about staging the patches via the vCenter Update Manager PowerCLI cmdlets by Damian Karlson. But there are no copy-past-run scripts available to update a vSphere host. So I fired up PowerGUI script editor and started working on a function called Update-VMHost. This function performs the following steps during the update process of a vSphere host:

  • Look for a baseline and attach it if necessary.
  • Perform a scan of the host.
  • Check for compliancy.
  • If not compliant enter Maintenance mode.
  • Show missing patches
  • When the host is in Maintenance mode, start the remediation process.
  • After the reboot of the host, exit Maintenance mode.
  • That’s pretty much it. If you want to use this function, you can copy it from the end of this post and paste it inside the PowerCLI screen.

Continue reading “PowerCLI: Update-VMHost Function”

PowerCLI: Easy NFS datastore setup


It’s a new year so let’s start with a new PowerCLI post. This post is inspired by the blog post of @alanrenouf: PowerCLI easy vswitch portgroup setup. I love the whole idea of taking a good working config from a vSphere host and use it on a fresh installed vSphere host to make sure it’s compliant.  In this post I will show you how to perform the same trick with NFS datastores like Alan did with the vSwithes and Portgroups.

My home lab contains two HP ml110 g5 and a simple P4 box with some hard disks to add shared storage to the lab. It’s running Debian linux and is capable of presenting iSCSI targets, NFS and SAMBA shares .I use NFS as shared storage for my vSphere lab.

On esx2.ict-freak.local I use the following NFS datastores:

image

But I messed up the configuration of the other vSphere host in my lab called esx1.ict-freak.local. So I had to reset the network settings and lost all the NFS datastores:

image

So I needed to add the five NFS shares. This is a nice task for PowerCLI and the New-Datastore cmdlet:

Update: I had to remove the last / from the Path variable. If you do not remove the last / the script will mount the NFS share but with a new UUID. See Damian Karlson his post about this subject here.

Continue reading “PowerCLI: Easy NFS datastore setup”

Release: PowerCLI 4.1.1


Just noticed the new release of PowerCLI 4.1.1 on twitter:

image

There are a lot of new features:

  • Added support for the ESX CLI functionality through the Get-EsxCli cmdlet.
  • Added support for ESX Top statistics through the Get-EsxTop cmdlet.
  • Enhanced Get-VirtualSwitch, Get-VirtualPortGroup, Get-VMHost, Get-VM, New-NetworkAdapter, Set-NetworkAdapter, and Get-VMHostNetworkAdapter to add support for distributed switches and distributed switch port groups.
  • Added support for SCSI controllers through the New-ScsiController, Get-ScsiController, and Set-ScsiController cmdlets, and the new Controller parameter of New-HardDisk and Set-HardDisk.
  • Added support for querying and modifying vCenter Server alarms through the Get-AlarmDefinition, Set-AlarmDefinition, Get-AlarmAction, New-AlarmAction, Remove-AlarmAction, Get-AlarmActionTrigger, New-AlarmActionTrigger, and Remove-AlarmActionTrigger cmdlets.
  • Added the Get-AdvancedSetting, Set-AdvancedSetting, New-AdvancedSetting, and Remove-AdvancedSetting cmdlets for managing advanced vCenter Server settings and Cluster HA advanced options.
  • Added the Wait-Tools cmdlet that allows you to wait for VMware Tools of the specified virtual machines to load before proceeding.
  • Added support for querying disk and disk partition information of hosts through the Get-VMHostDisk and Get-VMHostDiskPartition cmdlets.
  • Added support for formatting host disk partitions through the Format-VMHostDiskPartition cmdlet.
  • Added support for querying the primary HA cluster nodes through the Get-HAPrimaryVMHost cmdlet.
  • Added support for zeroing out a virtual machine hard disk through a new ZeroOut parameter to Set-HardDisk cmdlet.

looking forward to test the new Get-EsxCli and the Get-EsxTop cmdlets.

The complete change log is available here.

You can download the new release from here: download link.