View difference between Paste ID: NSn2RAeB and 6XJSghkD
SHOW: | | - or go back to the newest paste.
1
# Get all Clusters
2
$allclusters = Get-Cluster
3
4
# Iterate for each cluster and generate and save the vCenter Network map visio diagram.
5
foreach ($cluster in $allclusters)
6
7
{
8
9
10
$shpFile1 = "VMware EUC Visio Stencils 2015.vss"
11
 
12
#VISIO Function for the Connection-of-objects  
13
function connect-visioobject ($firstObj, $secondObj)  
14
{  
15
    $shpConn = $pagObj.Drop($pagObj.Application.ConnectorToolDataObject, 0, 0)  
16
    #// Connect its Begin to the 'From' shape:  
17
    $connectBegin = $shpConn.CellsU("BeginX").GlueTo($firstObj.CellsU("PinX"))  
18
    #// Connect its End to the 'To' shape:  
19
    $connectEnd = $shpConn.CellsU("EndX").GlueTo($secondObj.CellsU("PinX"))  
20
}  
21
 
22
#VISIO Function for adding the object into the drawing  
23
function add-visioobject ($mastObj, $item)  
24
{  
25
         Write-Host "Adding $item"  
26
        # Drop the selected stencil on the active page, with the coordinates x, y  
27
          $shpObj = $pagObj.Drop($mastObj, $x, $y)  
28
        # Enter text for the object  
29
          $shpObj.Text = $item
30
        #Return the visioobject to be used  
31
        return $shpObj  
32
 }  
33
 
34
# Create VI Properties to extract vmtype
35
36
New-VIProperty -Name GuestFamily -ObjectType VirtualMachine -ValueFromExtensionProperty 'guest.guestfamily' -Force | Out-Null
37
New-VIProperty -Name GuestOSType -ObjectType VirtualMachine -ValueFromExtensionProperty 'guest.guestfullname' -Force | Out-Null
38
39
40
# Create an instance of Visio and create a document based on the Basic Diagram template.  
41
$AppVisio = New-Object -ComObject Visio.Application  
42
$docsObj = $AppVisio.Documents  
43
$DocObj = $docsObj.Add("Basic Network Diagram.vst")  
44
 
45
# Set the active page of the document to page 1  
46
$pagsObj = $AppVisio.ActiveDocument.Pages  
47
$pagObj = $pagsObj.Item(1)  
48
 
49
# Load a set of stencils and select one to drop  
50
$stnPath = [system.Environment]::GetFolderPath('MyDocuments') + "\My Shapes\"  
51
$stnObj1 = $AppVisio.Documents.Add($stnPath + $shpFile1)  
52
$VirtualMachine = $stnobj1.Masters.item("Virtual Machine (3D)")  
53
$VirtualAppliance = $stnobj1.Masters.item("3D Virtual Appliance")  
54
$vSphere = $stnobj1.Masters.item("vSphere")
55
$Clusters = $stnobj1.Masters.item("Clusters 2")
56
$VMware_Host=$stnobj1.Masters.item("VMware Host")
57
$datastores=$stnobj1.Masters.item("Disks 1")
58
  
59
#Connect-VIServer "Your vCenter Name" -Credential (Get-Credential)
60
61
$allNODES = Get-Cluster $cluster | get-vmhost
62
$allclusters = Get-Cluster $cluster
63
$allVMs = Get-Cluster $cluster | Get-VM  
64
$allDs = Get-Cluster $cluster | Get-Datastore
65
66
 
67
#Set Start Locations of Objects  
68
$x = 1  
69
$y = .5  
70
 
71
#DRAW ALL Cluster-NODES  
72
Foreach ($cluster in $allclusters) {  
73
    $y += 0.25  
74
    $clusterInfo = "CLUSTER: " + $cluster.Name  
75
    $clusterObj = add-visioobject $Clusters $clusterInfo
76
  
77
#DRAW ALL Datastore's and connect them to the cluster object
78
    Foreach ($d in $allDs) {  
79
          
80
            $x = -3  
81
            $y += 1.5  
82
            $dsInfo = "Datastore: " + $d.Name  + "`nDSCapacity(GB): " + [math]::Round([decimal]$d.CapacityGB,2)
83
            $datastores = add-visioobject $datastores $dsInfo  
84
            connect-visioobject $clusterObj $datastores
85
    
86
    }
87
88
#DRAW ALL Physical VMHOST NODES with Node Name, Total Memory and vCenter version and connect them to the cluster object
89
    Foreach ($node in $allNODES) {  
90
          
91
            $x = 2  
92
            $y += 1.5  
93
            $nodeInfo = "NODE: " + $node.Name  + "`eSXIVersion: " + $node.Version + "`nTotalMemory(GB): " + [math]::Round([decimal]$node.MemoryTotalGB,2)
94
            $nodeObj = add-visioobject $VMware_Host $nodeInfo  
95
            connect-visioobject $clusterObj $nodeObj      
96
        
97
# GET All Virtual Machines and drwa them based on the OS type and connect them to the Node object.
98
$allVMNodes = Get-VMHost $node | Get-VM | select guestfamily,guestostype | Group-Object guestostype |?{$_.name -ne ''} | select name,count
99
                
100
        foreach ($vm in $allVMNodes) {   
101
        
102
            $x += 2          
103
            $y += 1.5
104
            $vmInfo = "VM_OSType: " + $vm.Name  + "`nNo_of_VM's: " + $vm.count
105
            $VirtualMachine = add-visioobject $VirtualMachine $vmInfo
106
            connect-visioobject $nodeObj $VirtualMachine  
107
        
108
        }  
109
110
        }
111
112
        }
113
114
# Resize the Visio so that all fits in one page, nice and clean.
115
$pagObj.ResizeToFitContents()  
116
117
# Save the Visio file generated in desktop for each of the cluster.
118
$DocObj.SaveAs("C:\Users\vinithm\Desktop\vmwarelabvisio\$cluster.vsd")
119
        
120
}