I’ve blogged about using PowerShell with various members of the Office family before. I thought its about time I looked at Visio. I use Visio quite a bit and it would be useful to be able to drive it with PowerShell
001
002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 |
## create visio document
$visio = New-Object -ComObject Visio.Application $docs = $visio.Documents ## use basic template ## set active page ## Add a stencil $server = $stencil.Masters.Item("Server") $shape1 = $page.Drop($server, 2, 2) $doc.SaveAs("c:\scripts\visio\draw1.vsd") |
Office still uses COM objects so we need to create a Viso object and then the document and page we are working on. We are using the basic template and are going to add a stencil for the Enterprise Applications. A couple of objects are created for the server and workstation shapes and then we drop them on to the page.
We can then save the drawing and quit visio.
A simple drawing that we will need to embellish but it shows how straight forward it is to automate the production of drawings. The great thing is that we can then go back into the drawing and manipulate it as we need.