PowerShell script exchange
Post Reply
StanO
Enthusiast
Posts: 36
Liked: 5 times
Joined: Jan 04, 2010 4:14 pm
Full Name: Stan
Contact:

Using powershell to add static mappings to Virtual Lab produces Set-VBRViVirtualLab : VM name cannot contains spaces.

Post by StanO »

I am attempting to script adding a large number of static IP mappings to our virtual labs and running into a snag.

Using the following:

Code: Select all

$server = Get-VBRServer -Name "esxh-02.my.tld"
$network = Get-VBRViServerNetworkInfo -Server $server | Where-Object {$_.NetworkName -eq "Primary Data Network"}
$mapping = New-VBRViVirtualLabIPMappingRule -ProductionNetwork $network -IsolatedIPAddress 10.48.0.102 -AccessIPAddress 11.48.0.102 -Note "DC-02"
$virtualLab = Get-VBRViVirtualLabConfiguration -Name "ESXH-02 vLab01"
Set-VBRViVirtualLab -VirtualLab $virtualLab -IpMappingRule $mapping
Produces:
Set-VBRViVirtualLab : VM name cannot contains spaces.
At line:1 char:1
+ Set-VBRViVirtualLab -VirtualLab $virtualLab -IpMappingRule $mapping
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-VBRViVirtualLab], Exception
+ FullyQualifiedErrorId : System.Exception,Veeam.Backup.PowerShell.Cmdlets.SetVBRViVirtualLab

I'm stumped on where a VM name is containing spaces as I am not explicitly specifying a VM name in any of my commands. Can anybody offer any guidance on this?

Also, as I mentioned, I am planning to use this script to add a significant number of static IP mappings to our virtual labs (much more efficient than adding them via the GUI). I'm concerned that the $mapping variable as defined above contains only a single IP mapping and the subsequent Set-VBRVirtualLab will not append entries to the list of static IP mappings, rather replace the single mapping provided by each iteration. Any guidance here would also be appreciated.

Thank you,

Stan
Mildur
Product Manager
Posts: 9848
Liked: 2607 times
Joined: May 13, 2017 4:51 pm
Full Name: Fabian K.
Location: Switzerland
Contact:

Re: Using powershell to add static mappings to Virtual Lab produces Set-VBRViVirtualLab : VM name cannot contains spaces

Post by Mildur »

Hi Stan
I'm stumped on where a VM name is containing spaces as I am not explicitly specifying a VM name in any of my commands. Can anybody offer any guidance on this?
You query your virtual lab configuration and with it the virtual lab proxy appliance with this command:
$virtualLab = Get-VBRViVirtualLabConfiguration -Name "ESXH-02 vLab01"

Can you check the virtual lab proxy configuration and if it contains spaces in its name? Spaces are not allowed for the virtual lab proxy appliance. Also please check the name in your vCenter/ESXI host.

Thanks
Fabian
Product Management Analyst @ Veeam Software
StanO
Enthusiast
Posts: 36
Liked: 5 times
Joined: Jan 04, 2010 4:14 pm
Full Name: Stan
Contact:

Re: Using powershell to add static mappings to Virtual Lab produces Set-VBRViVirtualLab : VM name cannot contains spaces

Post by StanO »

Hi Fabian,

I appreciate your response. The proxy appliance has no spaces in its name (ESXH-02_vLab01).

Thank you,
Stan
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Using powershell to add static mappings to Virtual Lab produces Set-VBRViVirtualLab : VM name cannot contains spaces

Post by oleg.feoktistov »

Hi Stan,

It is a bug. Though spaces in proxy appliance name are being replaced with underscores in the UI, it doesn't happen in powershell.
If you look at proxy appliance name property via PS, you'll see that spaces persist:

Code: Select all

$lab = Get-VBRViVirtualLabConfiguration
$lab.ProxyAppliance.Name
The fix is scheduled for v12.

Best regards,
Oleg
StanO
Enthusiast
Posts: 36
Liked: 5 times
Joined: Jan 04, 2010 4:14 pm
Full Name: Stan
Contact:

Re: Using powershell to add static mappings to Virtual Lab produces Set-VBRViVirtualLab : VM name cannot contains spaces

Post by StanO »

Thank you Oleg.
StanO
Enthusiast
Posts: 36
Liked: 5 times
Joined: Jan 04, 2010 4:14 pm
Full Name: Stan
Contact:

Re: Using powershell to add static mappings to Virtual Lab produces Set-VBRViVirtualLab : VM name cannot contains spaces

Post by StanO » 1 person likes this post

To close the loop on my second question (which is answered numerous times in other forum posts, but posted here to avoid the frustration of a question without an answer for future visitors). My original code has been modified as follows to add a list of static mappings to an existing Virtual Lab.

Code: Select all

#Specify ESXi Host Name
$server = Get-VBRServer -Name "esxh-02.my.tld"
#Specify Name of network to receive additional static IP mappings
$network = Get-VBRViServerNetworkInfo -Server $server | Where-Object {$_.NetworkName -eq "Primary Data Network"}
#Specify list of mappings to add
$newStaticMappings = & {
New-VBRViVirtualLabIPMappingRule -ProductionNetwork $network -IsolatedIPAddress 10.48.0.101 -AccessIPAddress 11.48.0.101 -Note "DC-01"
New-VBRViVirtualLabIPMappingRule -ProductionNetwork $network -IsolatedIPAddress 10.48.0.102 -AccessIPAddress 11.48.0.102 -Note "DC-02"
}
#Specify Name of Virtual Lab to add mappings to
$virtualLab = Get-VBRViVirtualLabConfiguration -Name "ESXH-02_vLab01"
#Concatenate existing and new static mappings into a single array
$staticMappings = $virtualLab.IpMappingRule + $newStaticMappings
#Display the combined list of Static Mappings
$staticMappings
#Apply the change to the appropriate Virtual Lab
Set-VBRViVirtualLab -VirtualLab $virtualLab -Type Advanced -EnableStaticIPMapping -IpMappingRule $staticMappings -Force
Thanks,

Stan
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests