{"id":1179,"date":"2013-02-12T10:00:57","date_gmt":"2013-02-12T15:00:57","guid":{"rendered":"http:\/\/enterpriseadmins.org\/blog\/?p=1179"},"modified":"2013-02-10T11:23:09","modified_gmt":"2013-02-10T16:23:09","slug":"network-related-vsphere-checks","status":"publish","type":"post","link":"https:\/\/enterpriseadmins.org\/blog\/scripting\/network-related-vsphere-checks\/","title":{"rendered":"Network related vSphere checks"},"content":{"rendered":"<p>The following two sections of code can be ran independently or used in conjunction with Alan Renouf&#8217;s vCheck script.  They return network specific issues that could happen in a vSphere environment. <\/p>\n<p>The first check makes use of a $clusters variable, which can be created using the following line of code:<\/p>\n<pre>\r\n$Clusters = Get-Cluster\r\n<\/pre>\n<p>The following section will report on any port groups that do not exist on all hosts in a cluster.  This is a fairly common issue with standard vSwitches, but is typically resolved by using Distributed vSwitches (for the Enterprise Plus users).<\/p>\n<pre><code class=\"language-1\">\r\n$networkListHT = @{}\r\nGet-View -ViewType Network -Property Name | %{ $networkListHT.Add($_.MoRef.value,$_.Name) }\r\n\r\n$portGroupCheck = @()\r\n$Clusters | Select Name, ID | %{\r\n\t$thisClusterName = $_.Name\r\n\t$thisClusterHosts = Get-View -ViewType HostSystem -SearchRoot $_.id -Property Name, Network\r\n\r\n\t$thisClusterNetworks = @()\r\n\t$thisClusterHosts | %{\r\n\t\t$thisHost = $_.Name\r\n\t\t$_.Network | %{ $thisClusterNetworks += New-Object psobject -Property @{ \"Port Group\"=$networkListHT[$_.Value]; Host=$thisHost; Cluster=$thisClusterName} }\r\n\t}\r\n\r\n\t$portGroupCheck += ($thisClusterNetworks | Group-Object -Property \"Port Group\" | ?{$_.Count -lt $thisClusterHosts.count} | Select -ExpandProperty Group | Sort Host )\r\n}\r\n\r\n$portGroupCheck\r\n<\/code><\/pre>\n<p>The following one liner will show any port group that does not have virtual machines.  This could be a new network that simply doesn&#8217;t have VMs yet, or an old network that is no longer required.<\/p>\n<pre><code class=\"language-powershell\">\r\nGet-View -ViewType Network -Property Name, VM, Host |?{@($_.VM).Count -eq 0} | Select Name, @{Name=\"Host Count\"; Expression={@($_.Host).Count}} | Sort Name\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The following two sections of code can be ran independently or used in conjunction with Alan Renouf&#8217;s vCheck script. They return network specific issues that could happen in a vSphere environment. The first check makes use of a $clusters variable, &hellip; <a href=\"https:\/\/enterpriseadmins.org\/blog\/scripting\/network-related-vsphere-checks\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-1179","post","type-post","status-publish","format-standard","hentry","category-scripting","category-virtualization"],"_links":{"self":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1179","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/comments?post=1179"}],"version-history":[{"count":2,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1179\/revisions"}],"predecessor-version":[{"id":1181,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1179\/revisions\/1181"}],"wp:attachment":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/media?parent=1179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/categories?post=1179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/tags?post=1179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}