{"id":51573,"date":"2010-01-13T00:01:00","date_gmt":"2010-01-13T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2010\/01\/13\/hey-scripting-guy-can-i-use-wmi-and-windows-powershell-to-make-a-microsoft-visio-drawing\/"},"modified":"2010-01-13T00:01:00","modified_gmt":"2010-01-13T00:01:00","slug":"hey-scripting-guy-can-i-use-wmi-and-windows-powershell-to-make-a-microsoft-visio-drawing","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-can-i-use-wmi-and-windows-powershell-to-make-a-microsoft-visio-drawing\/","title":{"rendered":"Hey, Scripting Guy! Can I Use WMI and Windows PowerShell to Make a Microsoft Visio Drawing?"},"content":{"rendered":"<p class=\"MsoNormal\">&nbsp;<a class=\"addthis_button\" href=\"http:\/\/www.addthis.com\/bookmark.php?v=250&amp;pub=scriptingguys\"><img decoding=\"async\" alt=\"Bookmark and Share\" src=\"http:\/\/s7.addthis.com\/static\/btn\/v2\/lg-share-en.gif\" width=\"125\" height=\"16\"><\/a><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p><font size=\"2\"><img decoding=\"async\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"><\/font><\/p>\n<p class=\"MsoNormal\">&nbsp;Hey, Scripting Guy! Using Windows PowerShell to control Microsoft Visio looks really cool. However, if I have to manually enter all of the data in the script to produce the drawing, it is probably easier to open Microsoft Visio, drag and drop the shapes from the stencils, and add the connectors. However, I will say that using the <b>autoconnect<\/b> script feature is much easier than dragging and dropping a bunch of connectors. Is there a way to integrate a Windows PowerShell script with a few Windows Management Instrumentation (WMI) queries, and use that information to make the drawing? If that could be done, I could run a script and easily document my network. <\/p>\n<p class=\"MsoNormal\">&#8212; SA<\/p>\n<p class=\"MsoNormal\">\n<p>&nbsp;<\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\">Hello SA, <\/p>\n<p class=\"MsoNormal\">Microsoft Scripting Guy Ed Wilson here. A day without meetings is&hellip;well, like a day without meetings. With no meetings during a day, it is amazing how productive one can be. I have <a href=\"http:\/\/en.wikipedia.org\/wiki\/Carl_Weathersby\"><font face=\"Segoe\">Carl Weathersby<\/font><\/a> cranked up on my <a href=\"http:\/\/zune.net\/en-us\/products\/zunehd\/default.htm\"><font face=\"Segoe\">Zune HD<\/font><\/a> and am sipping a cup of English breakfast with a cinnamon stick and lemon grass. The Scripting Wife made some cranberry nut scones to go with the tea. This is the first day of the New Year on the East Coast of the United States, and it is shaping up to be a wonderful day. Because I have spent so much time outside of United States in recent years, I was unaware of what people in Charlotte do for New Year&rsquo;s Eve, so the Scripting Wife and I spent last night watching a <i>Get Smart<\/i> marathon. My thoughtful present to her this year was the complete works. One of my favorite places to spend New Year&rsquo;s Eve is Quebec City in Canada. I was up there for a month teaching Windows PowerShell workshops. As seen in the following image, winter up there can be very cool.<\/p>\n<p class=\"Fig-Graphic\"><img decoding=\"async\" title=\"Image of winter in Quebec City\" alt=\"Image of winter in Quebec City\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/january\/hey0113\/hsg-01-13-10-01.jpg\" width=\"600\" height=\"450\"><\/p>\n<p class=\"MsoNormal\">It is a relaxing day and a fun time to mellow out, spend some extra time writing scripts, and catch up on e-mail sent to <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\"><font face=\"Segoe\">scripter@microsoft.com<\/font><\/a>. An ear infection is keeping me from going out to my woodworking shop or swimming, so I may as well write some scripts and answer e-mail. We can watch <i>Get Smart<\/i> later.<\/p>\n<p class=\"MsoNormal\">SA, I wrote the ComputerConfigDrawing.ps1 script for you to illustrate how to incorporate WMI data into a Microsoft Visio drawing that you generate by calling a Windows PowerShell script. The complete ComputerConfigDrawing.ps1 script is seen here. <\/p>\n<p class=\"MsoNormal\"><b>ComputerConfigDrawing.ps1<\/p>\n<p><\/b><\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">Param($computer = &#8220;LocalHost&#8221;)<\/p>\n<p># *** Wmi Functions ***<br \/>Function Get-ComputerSystem ($computer)<br \/>{<br \/><span>&nbsp;<\/span>Get-WmiObject -Class win32_computersystem -ComputerName $computer <br \/>} #end Get-ComputerSystem<\/p>\n<p>Function Get-DesktopMonitor($computer)<br \/>{<br \/><span>&nbsp;<\/span>Get-WmiObject -Class win32_desktopmonitor -ComputerName $computer<br \/>} #end Get-DesktopMonitor<\/p>\n<p>Function Get-DefaultPrinter ($computer)<br \/>{<br \/><span>&nbsp;<\/span>Get-WmiObject -Class win32_printer -ComputerName $Computer `<br \/><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>-Filter &#8220;default = $true&#8221;<br \/>} #end Get-DefaultPrinter<\/p>\n<p>Function Get-NetworkAdapterConfiguration ($computer)<br \/>{<br \/><span>&nbsp;<\/span>Get-WmiObject -Class win32_networkadapterconfiguration `<br \/><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>-ComputerName $computer -Filter &#8220;ipenabled = $true&#8221;<br \/>} #end Get-NetworkAdapterConfiguration<\/p>\n<p>$application = New-Object -ComObject Visio.Application<br \/>$application.visible = $false<br \/>$documents = $application.Documents<br \/>$document = $documents.Add(&#8220;Basic Network Diagram.vst&#8221;)<br \/>$pages = $application.ActiveDocument.Pages<br \/>$page = $pages.Item(1)<\/p>\n<p>$NetworkStencil = $application.Documents.Add(&#8220;periph_m.vss&#8221;)<br \/>$ComputerStencil = $application.Documents.Add(&#8220;Computers and Monitors.vss&#8221;)<br \/>$ConnectorStencil = $application.Documents.Add(&#8220;Connectors.vss&#8221;)<\/p>\n<p>$pcinfo = Get-ComputerSystem -computer $computer<br \/>$pc = $ComputerStencil.Masters.Item(&#8220;PC&#8221;)<br \/>$shape1 = $page.Drop($pc, 2.2, 6.8) <br \/>$shape1.Text = &#8220;$($pcinfo.DNSHostName)`r`n$($pcinfo.Domain)&#8221;<\/p>\n<p>$monitorinfo = Get-DesktopMonitor -computer $computer<br \/>$Monitor = $ComputerStencil.Masters.Item(&#8220;LCD monitor&#8221;)<br \/>$shape2 = $page.Drop($Monitor, 5.0, 4.5) <br \/>$shape2.Text = &#8220;$($monitorinfo.name)<br \/>$($monitorinfo.ScreenHeight) x $($monitorinfo.ScreenWidth)&#8221;<\/p>\n<p>$printerinfo = Get-DefaultPrinter -computer $computer<br \/>$Printer = $NetworkStencil.Masters.Item(&#8220;Printer&#8221;)<br \/>$shape3 = $page.Drop($Printer,6.0,3.0)<br \/>$shape3.Text = &#8220;$($printerinfo.deviceID)<br \/>$($printerinfo.PortName)`r`n$($printerinfo.Location)&#8221;<\/p>\n<p>$networkinfo = Get-NetworkAdapterConfiguration -computer $computer<br \/>$Router = $NetworkStencil.Masters.Item(&#8220;Router&#8221;)<br \/>$shape4 = $page.Drop($Router,7.0,1.5)<br \/>$shape4.Text = &#8220;$($networkinfo.DefaultIPGateWay)&#8221;<\/p>\n<p>$User = $NetworkStencil.Masters.Item(&#8220;User&#8221;)<br \/>$shape5 = $page.Drop($User,4.0,6.0)<br \/>$shape5.Text = &#8220;$($pcinfo.UserName)&#8221;<\/p>\n<p>$etherNet = $NetworkStencil.Masters.Item(&#8220;Ethernet&#8221;)<br \/>$shape6 = $page.Drop($etherNet,2.2, 1.0)<br \/>$shape6.Text = &#8220;$(($networkinfo.IPAddress)[0])&#8221;<\/p>\n<p>$connector = $ConnectorStencil.Masters.item(&#8220;Dynamic Connector&#8221;)<br \/>$shape1.AutoConnect($shape6, 0, $connector)<br \/>$shape2.AutoConnect($shape6, 0, $connector)<br \/>$shape3.AutoConnect($shape6, 0, $connector)<br \/>$shape4.AutoConnect($shape6, 0, $connector)<br \/>$shape5.AutoConnect($shape6, 0, $connector)<\/p>\n<p>$page.CenterDrawing()<br \/>$document.SaveAs(&#8220;C:fsoComputerConfig.vsd&#8221;)<br \/>$application.Quit()<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">The first thing to do in the ComputerConfigDrawing.ps1 script is to create a command-line parameter to allow you to change the target system. Next, the <b>Get-ComputerSystem<\/b> function is used to return some information about the target computer.<\/p>\n<p class=\"Readeraidonly\">For more information about functions, see the <a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/tags\/getting+started\/Windows+PowerShell\/default.aspx\"><font face=\"Segoe\">Function Week<\/font><\/a> Hey, Scripting Guy! posts, or check out the <a href=\"http:\/\/bit.ly\/BestPractice\"><font face=\"Segoe\">Windows PowerShell 2.0 Best Practices<\/font><\/a> book from Microsoft Press. For more information about using WMI and Windows PowerShell, check out the <a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2009\/12.aspx\"><font face=\"Segoe\">WMI Week Hey, Scripting Guy! posts<\/font><\/a>.<\/p>\n<p class=\"MsoNormal\">The <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa394102(VS.85).aspx\"><font face=\"Segoe\">Win32_ComputerSystem<\/font><\/a> WMI class is used with the <b>Get-WMiObject<\/b> cmdlet and the target computer supplied to the <b>&ndash;computername<\/b> parameter. The entire <b>Win32_ComputerSystem<\/b> WMI class information will be returned to the script when the <b>Get-ComputerSystem<\/b> function is called:<\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">Param($computer = &#8220;LocalHost&#8221;)<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">Function Get-ComputerSystem ($computer)<br \/>{<br \/>Get-WmiObject -Class win32_computersystem -ComputerName $computer <br \/>} #end Get-ComputerSystem<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">To get information about the monitor that is attached to the computer, the <b>Win32_DesktopMonitor<\/b> WMI class is called by the <b>Get-DesktopMonitor<\/b> function. Depending on the make of your computer and monitor, you may or may not be able to retrieve specific information about the model of your monitor:<\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">Function Get-DesktopMonitor($computer)<br \/>{<br \/>Get-WmiObject -Class win32_desktopmonitor -ComputerName $computer<br \/>} #end Get-DesktopMonitor<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">When you use the <b>Win32_Printer<\/b> WMI class to return information about printers defined on a computer, you will almost always return a lot of things that are not really printers such as the Microsoft XPS Document printer, a fax machine, and even some image capturing software. I want to know about the default printer; to do this, I use the <b>&ndash;filter<\/b> parameter and limit the instances of the <b>Win32_Printer<\/b> WMI class to printers that have the <b>default<\/b> property set to <b>$true<\/b>. This is seen here:<\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">Function Get-DefaultPrinter ($computer)<br \/>{<br \/>Get-WmiObject -Class win32_printer -ComputerName $Computer `<br \/><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>-Filter &#8220;default = $true&#8221;<br \/>} #end Get-DefaultPrinter<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">If the bogus printers returned by the WMI class <b>Win32_Printer<\/b> are upsetting, the results returned by <b>Win32_networkadapterconfiguration<\/b> are completely out of control. On my computer, I have one real network card, and yet 12 instances are returned. One technique to reduce the number of bogus network adapters is to filter the ones that are <b>IPenabled<\/b>. This does not always work (it depends on your computer and your network configuration), but it will at least point you in the right direction:<\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">Function Get-NetworkAdapterConfiguration ($computer)<br \/>{<br \/>Get-WmiObject -Class win32_networkadapterconfiguration `<br \/><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>-ComputerName $computer -Filter &#8220;ipenabled = $true&#8221;<br \/>} #end Get-NetworkAdapterConfiguration<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">With the WMI functions out of the way, it is time to create a Visio drawing using some Windows PowerShell code. This portion of the script is similar to <a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2010\/01\/12\/hey-scripting-guy-january-12-2010.aspx\">yesterday&rsquo;s Hey, Scripting Guy! post<\/a>:<\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">$application = New-Object -ComObject Visio.Application<br \/>$application.visible = $false<br \/>$documents = $application.Documents<br \/>$document = $documents.Add(&#8220;Basic Network Diagram.vst&#8221;)<br \/>$pages = $application.ActiveDocument.Pages<\/p>\n<p>$page = $pages.Item(1)<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">$NetworkStencil = $application.Documents.Add(&#8220;periph_m.vss&#8221;)<br \/>$ComputerStencil = $application.Documents.Add(&#8220;Computers and Monitors.vss&#8221;)<br \/>$ConnectorStencil = $application.Documents.Add(&#8220;Connectors.vss&#8221;)<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">Next, it is time to call the <b>Get-ComputerSystem<\/b> function to retrieve the computer host name and the domain. The <b>Get-ComputerSystem<\/b> function returns all of the information contained in the <b>Win32_ComputerSystem<\/b> WMI class. You could therefore modify the shape1 <b>text<\/b> property to include the additional information from that class:<\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">$pcinfo = Get-ComputerSystem -computer $computer<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">After the <b>$pcinfo<\/b> variable contains the computer information from the <b>Get-ComputerSystem<\/b> function, it is time to drop a <b>PC<\/b> shape from the <b>Computer<\/b> stencil onto the Microsoft Visio drawing. Because of the way that Windows PowerShell returns WMI information, you will need to use the subexpression <b>$()<\/b> to prevent the unraveling of the object inside the expanding string (the double quotation marks). The <b>`r`n<\/b> character sequence is used to create a carriage return line feed (VBScript: vbcrlf) to continue the domain information onto the second line under the host name. This is seen here:<\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">$pc = $ComputerStencil.Masters.Item(&#8220;PC&#8221;)<br \/>$shape1 = $page.Drop($pc, 2.2, 6.8) <br \/>$shape1.Text = &#8220;$($pcinfo.DNSHostName)`r`n$($pcinfo.Domain)&#8221;<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">The <b>Get-DesktopMonitor<\/b> function is used to retrieve the monitor information. Store the returned WMI object in the <b>$monitorinfo<\/b> variable, as seen here:<\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">$monitorinfo = Get-DesktopMonitor -computer $computer<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">Next, retrieve an <b>LCD Monitor<\/b> shape from the <b>Computer<\/b> stencil and store the shape in the <b>$monitor<\/b> variable. Drop the shape onto the Microsoft Visio drawing and retrieve the <b>monitor name<\/b> property and place it on the first line. By continuing the string to the second line, you can avoid needing to use the <b>`r`n<\/b> to add a second line. The monitor resolution will be displayed as screen height by screen width on a single line. This section of the code is seen here:<\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">$Monitor = $ComputerStencil.Masters.Item(&#8220;LCD monitor&#8221;)<br \/>$shape2 = $page.Drop($Monitor, 5.0, 4.5) <br \/>$shape2.Text = &#8220;$($monitorinfo.name)<br \/>$($monitorinfo.ScreenHeight) x $($monitorinfo.ScreenWidth)&#8221;<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">Next, the <b>Get-DefaultPrinter<\/b> function is used to retrieve information about the default printer and store it in the <b>$printerinfo<\/b> variable:<\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">$printerinfo = Get-DefaultPrinter -computer $computer<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">The <b>Printer<\/b> shape comes from the <b>Network Peripherals<\/b> stencil and is stored in the <b>$printer<\/b> variable. The <b>name<\/b>, <b>port name<\/b>, and <b>location<\/b> properties are added to the <b>text<\/b> property of shape3, as seen here:<\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">$Printer = $NetworkStencil.Masters.Item(&#8220;Printer&#8221;)<br \/>$shape3 = $page.Drop($Printer,6.0,3.0)<br \/>$shape3.Text = &#8220;$($printerinfo.deviceID)<br \/>$($printerinfo.PortName)`r`n$($printerinfo.Location)&#8221;<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">Network information is retrieved by the <b>Get-NetworkAdapterConfiguration<\/b> function and stored in the <b>$networkinfo<\/b> variable:<\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">$networkinfo = Get-NetworkAdapterConfiguration -computer $computer<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">The <b>Router<\/b> shape is retrieved from the <b>Network Peripherals<\/b> stencil and stored in the <b>$router<\/b> variable. The IP address of the router comes from the <b>defaultIPGateway<\/b> property from the <b>Win32_networkadapterconfiguration<\/b> WMI class. This is shown here:<\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">$Router = $NetworkStencil.Masters.Item(&#8220;Router&#8221;)<br \/>$shape4 = $page.Drop($Router,7.0,1.5)<br \/>$shape4.Text = &#8220;$($networkinfo.DefaultIPGateWay)&#8221;<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">A <b>User<\/b> stencil is obtained from the <b>Network Peripherals<\/b> stencil and stored in the <b>$user<\/b> variable. The user name of the current user is obtained from the computer information that was stored in the <b>$pcinfo<\/b> variable earlier. This section of the script is seen here:<\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">$User = $NetworkStencil.Masters.Item(&#8220;User&#8221;)<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">$shape5 = $page.Drop($User,4.0,6.0)<br \/>$shape5.Text = &#8220;$($pcinfo.UserName)&#8221;<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">The IP address of the workstation is retrieved from the network information stored in the <b>$networkinfo<\/b> variable. The <b>IPAddress<\/b> property of the <b>Win32_NetworkAdapterConfiguration<\/b> WMI class is an array on Windows Vista and later that returns both IPV4 and IPV6 information. The IPV4 address is stored in element 0 of the array. For this script, we are ignoring the IPV6 address that is stored in element 1 of the array. This is assigned to the <b>text<\/b> property of the <b>Ethernet<\/b> shape, as shown here:<\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">$etherNet = $NetworkStencil.Masters.Item(&#8220;Ethernet&#8221;)<br \/>$shape6 = $page.Drop($etherNet,2.2, 1.0)<br \/>$shape6.Text = &#8220;$(($networkinfo.IPAddress)[0])&#8221;<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">All that remains is to connect the shapes, center the drawing, save, and close everything. This is the same as the code used in <a href=\"http:\/\/blogs.technet.com\/heyscriptingguy\/archive\/2010\/01\/12\/hey-scripting-guy-january-12-2010.aspx\">yesterday&rsquo;s Hey, Scripting Guy! post<\/a>. <\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">$connector = $ConnectorStencil.Masters.item(&#8220;Dynamic Connector&#8221;)<br \/>$shape1.AutoConnect($shape6, 0, $connector)<br \/>$shape2.AutoConnect($shape6, 0, $connector)<br \/>$shape3.AutoConnect($shape6, 0, $connector)<br \/>$shape4.AutoConnect($shape6, 0, $connector)<br \/>$shape5.AutoConnect($shape6, 0, $connector)<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">$page.CenterDrawing()<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"CodeBlockScreened\"><font><font face=\"Lucida Sans Typewriter\">$document.SaveAs(&#8220;C:fsoComputerConfig.vsd&#8221;)<br \/>$application.Quit()<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">When the ComputerConfigDrawing.ps1 script runs, the following drawing is displayed. <\/p>\n<p class=\"Fig-Graphic\"><img decoding=\"async\" title=\"Image of drawing displayed when script is run\" alt=\"Image of drawing displayed when script is run\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/january\/hey0113\/hsg-01-13-10-02.jpg\" width=\"600\" height=\"431\"><\/p>\n<p class=\"MsoNormal\">SA, that is all there is to using Microsoft Visio to create a drawing of your computer configuration. The script for today can also be found at the <a href=\"http:\/\/bit.ly\/8XlwB3\">Script Repository<\/a>. &nbsp;Microsoft Visio Week will continue tomorrow. <\/p>\n<p class=\"MsoNormal\">If you want to know exactly what we will be looking at tomorrow, follow us on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> or <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\"><font face=\"Segoe\">Facebook<\/font><\/a>. If you have any questions, send e-mail to us at <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\" target=\"_blank\"><font face=\"Segoe\">scripter@microsoft.com<\/font><\/a> or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\"><font face=\"Segoe\">Official Scripting Guys Forum<\/font><\/a>. See you tomorrow. Until then, peace.<\/p>\n<p>&nbsp;<\/p>\n<\/p>\n<p><b><span>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/span><\/b><\/p>\n<p>&nbsp;<\/p>\n<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; &nbsp; &nbsp;Hey, Scripting Guy! Using Windows PowerShell to control Microsoft Visio looks really cool. However, if I have to manually enter all of the data in the script to produce the drawing, it is probably easier to open Microsoft Visio, drag and drop the shapes from the stencils, and add the connectors. However, I [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[53,49,3,45],"class_list":["post-51573","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-microsoft-visio","tag-office","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>&nbsp; &nbsp; &nbsp;Hey, Scripting Guy! Using Windows PowerShell to control Microsoft Visio looks really cool. However, if I have to manually enter all of the data in the script to produce the drawing, it is probably easier to open Microsoft Visio, drag and drop the shapes from the stencils, and add the connectors. However, I [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/51573","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=51573"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/51573\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=51573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=51573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=51573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}