Add text or label to a connector in visio in Powershell

1.4k views Asked by At

I am in the process of trying to create a number of Visio diagrams based on servers connected to one another by port numbers. I have been able to create the servers and the connectors, however, I am running into an issue where I am unable to label or add text to a connector between two server shapes. Here is the part of the code that was originally from the Scripting Guy column:

...

$networkinfo = Get-NetworkAdapterConfiguration -computer $computer
$Router = $NetworkStencil.Masters.Item("Router")
$shape4 = $page.Drop($Router,7.0,2.5)
$shape4.Text = "$($networkinfo.DefaultIPGateWay)"

$User = $NetworkStencil.Masters.Item("User")
$shape5 = $page.Drop($User,4.0,6.0)
$shape5.Text = "$($pcinfo.UserName)"

$etherNet = $NetworkStencil.Masters.Item("Ethernet")
$shape6 = $page.Drop($etherNet,2.2, 1.0)
$shape6.Text = "$(($networkinfo.IPAddress)[0])"

$connector = $ConnectorStencil.Masters.item("Dynamic Connector")
$shape1.AutoConnect($shape6, 0, $connector)
$shape2.AutoConnect($shape6, 0, $connector)
$shape3.AutoConnect($shape6, 0, $connector)
$shape4.AutoConnect($shape6, 0, $connector)
$shape5.AutoConnect($shape6, 0, $connector)

Can anyone help me figure out how to add text or labels to the connector between the servers?

1

There are 1 answers

4
Mike Shepard On

After you do the autoconnect, try this:

$arrow=$page.Shapes('Dynamic Connector') | select-object -first 1
$arrow.NameU='Unique name for this arrow'
$arrow.Text='Label for the arrow'