network mapping command line

PowerShell script exchange

network mapping command line

Veeam Logoby daniel.Soares » Mon Jun 04, 2012 4:30 pm

Hello

is there a comandlet able to map the source and destination networks in veeam B&R 6 for replication jobs?
and a commandlet able to set all disks in thin format for destination vm

Daniel
daniel.Soares
Influencer
 
Posts: 17
Liked: never
Joined: Mon Sep 12, 2011 12:26 pm
Full Name: daniel soares

Re: network mapping command line

Veeam Logoby knight » Wed Jan 02, 2013 5:46 pm

Daniel, I am interested in these options also, did you resolve this?
knight
Novice
 
Posts: 5
Liked: never
Joined: Thu May 24, 2012 9:35 pm

Re: network mapping command line

Veeam Logoby knight » Wed Jan 02, 2013 9:20 pm

I opened a support case on this and was told "currently through our existing powershell cmdlets, you can not change the Network Mapping or the Thick Provisioning for the replicas. You would be able to do these options through powershell by exposing the .NET code that our software uses, but this method would be unsupported and the jobs would need to be re-created if they were broke using this method. We do not write scripts to do these behaviors as it is unsupported. Your best bet would be to make a thread on the powershell forum on forums.veeam.com and see if someone there can help you out on doing this."

Has anyone else been able to remap the networks when building a job via powershell script?

Is there a way to see what the script for an existing job looks like behind the GUI?
knight
Novice
 
Posts: 5
Liked: never
Joined: Thu May 24, 2012 9:35 pm

Re: network mapping command line

Veeam Logoby Sethbartlett » Thu Jan 03, 2013 10:13 pm

There is no such thing as "script for an existing job". All the jobs through the GUI are built by actual C# code and not by powershell. There should be a way to do the network mapping through powershell, but it would not be a supported cmdlet. I could probably figure out a way to do so.
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Sethbartlett
Expert
 
Posts: 282
Liked: 25 times
Joined: Wed Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett

Re: network mapping command line

Veeam Logoby knight » Fri Jan 04, 2013 6:44 pm

thanks for the response and clarifications Seth. Please let me know what you are able to figure out for the remapping.
knight
Novice
 
Posts: 5
Liked: never
Joined: Thu May 24, 2012 9:35 pm

Re: network mapping command line

Veeam Logoby tsightler » Fri Sep 06, 2013 4:39 pm

Interestingly I've had the request to do network mapping for a replica job via Powershell come up 3 times in the last few weeks so I finally say down and figured out a way to do it. By far the easiest way is to simple create a "template job" which has the appropriate network mapping and then simply copy the network mapping options from one job to another like this:
Code: Select all
$template_job = Get-VBRJob –Name “<Template_Job>”
$new_job = Get-VBRJob -Name "<New_Job>"
$new_job.Options.ViNetworkMappingOptions.NetworkMapping = $template_job.Options.ViNetworkMappingOptions.NetworkMapping
$new_job.SetOptions($new_job.Options)

This works great as long as the target job is brand new and has no existing network mapping options configured. However, sometimes there comes a need to update existing jobs with new network mapping settings. In this case the above code does not work and simply silently fails to update the target job. Unfortunately I was unable to find any supported method to update an existing jobs network mapping via Powershell, however, this was critical functionality for this customer so I decided to pursue a more unorthodox approach (i.e. unsupported). It turns out that the network mapping settings are stored in the Veeam B&R database as part of the "options" field for the job, which contains an XML object that describes the various advanced settings for the job. Since it's fairly easy to manipulate XML via Powershell I decided I should be able to delete existing network mapping settings from the XML and update the database directly, then use the copy technique above. The code below is what I came up with.

*** Please note that this is unsupported. It is shared here as the only method I could figure out to address updating network mapping settings via Powershell. While I believe it is low risk, and it hasn't caused any problems in the environments where it's being used, there's no guarantee that it will not break your environment. If it does, you get to keep all of the pieces. Make sure you have a good B&R configuration backup prior to running! ***

Code: Select all
asnp VeeamPSSnapin

$JobTemplate = "<Template_Job>"  # Replication Template
$JobName = "<Replication_Job>"  # Name of Job to Update
$DBServer = "<SQL_Server>" # Name of SQL Server/Instance
$DBName = "VeeamBackup" # Name of SQL Database for Veeam Backup Configuration

# Setup SQL server connection
$SqlConn = New-Object System.Data.SqlClient.SqlConnection
$SqlConn.ConnectionString = "Server=$DBServer;Database=$DBName;Integrated Security=True"
$SqlConn.Open()
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.Connection = $SqlConn

# Grab XML options for job from SQL table, load into Powershell XML object
$SqlCmd.CommandText = "select options from dbo.BJobs where name = '$JobName'"
$JobOptionsXML = [xml]$SqlCmd.ExecuteScalar()

# Remove the current NetworkMappings node from the XML if it exist
if ($JobOptionsXML.JobOptionsRoot.NetworkMappings) {
    $JobOptionsXML.JobOptionsRoot.RemoveChild($JobOptionsXML.JobOptionsRoot.NetworkMappings)
}

# Update the XML back to the SQL options field
$JobOptions = $JobOptionsXML.InnerXML
$SqlCmd.CommandText = "update dbo.Bjobs set options = '$JobOptions' where name = '$JobName'"
$SqlCmd.ExecuteNonQuery()

# Close the SQL Connection
$SqlConn.Close()

# Finally copy options from Template job to the Target job
$Job = Get-VBRJob –Name “$JobName”
$NetworkMapping = (Get-VBRJob -Name "$JobTemplate").Options.ViNetworkMappingOptions.NetworkMapping
$Job.Options.ViNetworkMappingOptions.NetworkMapping = $NetworkMapping
$Job.SetOptions($Job.Options)
tsightler
Veeam Software
 
Posts: 4768
Liked: 1737 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler


Return to PowerShell



Who is online

Users browsing this forum: Google [Bot] and 5 guests