PowerShell script exchange
Post Reply
daniel.Soares
Influencer
Posts: 17
Liked: never
Joined: Sep 12, 2011 12:26 pm
Full Name: daniel soares
Contact:

network mapping command line

Post by daniel.Soares »

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
knight
Novice
Posts: 5
Liked: never
Joined: May 24, 2012 9:35 pm
Contact:

Re: network mapping command line

Post by knight »

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

Re: network mapping command line

Post by knight »

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?
Sethbartlett
Veteran
Posts: 282
Liked: 26 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: network mapping command line

Post by Sethbartlett »

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.
knight
Novice
Posts: 5
Liked: never
Joined: May 24, 2012 9:35 pm
Contact:

Re: network mapping command line

Post by knight »

thanks for the response and clarifications Seth. Please let me know what you are able to figure out for the remapping.
tsightler
VP, Product Management
Posts: 6009
Liked: 2843 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: network mapping command line

Post by tsightler »

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) 
thomas.biesmans
Enthusiast
Posts: 36
Liked: 13 times
Joined: Mar 22, 2013 10:35 am
Contact:

Re: network mapping command line

Post by thomas.biesmans »

Just an update. In 9.5 U2 tsigthler's PowerShell does not silently fail and can be used to add network mappings through the use of a template job!
Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests