-
Notifications
You must be signed in to change notification settings - Fork 1
/
VM Network Details
112 lines (112 loc) · 4.52 KB
/
VM Network Details
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#Give all the login
$data1 = Import-Csv c:\E1000.csv
foreach($data in $data1 )
{
$vcenter = $data.VC
$vcenter_user = $data.VC_User_ID
$pass2 = $data.VC_Password
Connect-VIServer $vcenter -User $vcenter_user -Password $pass2
$vmname = $data.VM_Name
$username = $data.VC_User_ID
$password = $data.VC_Password
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$GuestCred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
#######
$tools_report = Get-View -ViewType virtualmachine -Filter @{"name" = "$vmname"}
if (($tools_report.guest.ToolsStatus -ne "toolsOk") -or ($tools_report.guest.ToolsVersionStatus -eq "guestToolsNeedUpgrade"))
{
Write-Host "The VMtools are not running or hardware vertion is old for the VM"
Write-Host "upgrading the VMtools it will NOT Reboot the server"
#Update-Tools -VM $vmname -NoReboot
}
if(($tools_report.guest.ToolsRunningStatus -eq "guestToolsNotRunning") -and ($tools_report.Config.Version -eq "vmx-04"))
{
Write-Host "the Vm tools are not running the so upgrade can not happen"
Disconnect-VIServer $global:DefaultVIServers -Confirm:$false
}
#######
#Get all the nic and os adapter details
$net_adp = Get-NetworkAdapter -VM $vmname | where {$_.type -eq "E1000"}
$rr = Get-VMGuestNetworkInterface -VM $vmname -GuestCredential $GuestCred
foreach ($nic in $net_adp)
{
$port_grup_name = $nic.NetworkName
$port_group = ($nic | select NetworkName).NetworkName
$mac = ($nic | select MacAddress).MacAddress
$name_nic = $nic.Name
foreach($guest_adp in $rr)
{
$name_nic = $net_adp.Name
$name_adapter = (($guest_adp | select name)).name
$ipaddr = ($guest_adp | Select-Object ip).ip
$subnet = ($guest_adp | select subnetmask).subnetmask
$gateway = ($guest_adp | select defaultgateway).defaultgateway
$pdnswins = ($guest_adp | select dns).dns[0]
$sdnswins = ($guest_adp | select dns).dns[1]
$ip_policy = $guest_adp.IPPolicy
$mac1 = ($guest_adp | select mac).mac
$mac2 = $mac1.replace("-" , ":")
if($mac -eq $mac2)
{
#check the vm is reachable from outside
#--------------------#
$hostname = $tools_report.Guest.HostName
$IP = $hostname
$ping = New-Object System.Net.NetworkInformation.Ping
try
{
$status = [string]($ping.Send($IP)).Status
$address = [string]($ping.Send($IP)).Address
}
catch [System.Net.NetworkInformation.PingException]{$status = $null}
switch($status)
{
Success
{
Write-Host "$vm is up with IP: $address" -foregroundcolor Green
$NewString = "$vm is up with IP: $address"
}
Default
{
Write-Host "$vmname not responding. IP: $IP Power State: $PowerState Network: $NetworkName Network Connected: $connState" -foregroundcolor RED
$NewString = "$vm not responding. IP: $IP Power State: $PowerState Network: $NetworkName Network Connected: $connState"
disconnect-viserver $global:DefaultVIServers -Confirm:$false
}
}
#--------------------#
$vln_ID_modified = ".$vln_ID."
$match_gateway = $gateway.Split(".")
$match_Ipaddr = $ipaddr.Split(".")
if((($match_Ipaddr[0] -eq $match_gateway[0]) -and ($match_Ipaddr[1] -eq $match_gateway[1]) -and ($match_Ipaddr[2] -eq $match_gateway[2]) -and ($ip_policy -eq "static") ) -or ($ipaddr -eq $address))
{
$name_nic = $net_adp.Name
$name_adapter = (($guest_adp | select name)).name
$ipaddr = ($guest_adp | Select-Object ip).ip
$subnet = ($guest_adp | select subnetmask).subnetmask
$gateway = ($guest_adp | select defaultgateway).defaultgateway
$pdnswins = ($guest_adp | select dns).dns[0]
$sdnswins = ($guest_adp | select dns).dns[1]
$ip_policy = $guest_adp.IPPolicy
$get_details += @($guest_adp | select ip,subnetmask,defaultgateway,
@{n = "primery DNS" ; e = {$pdnswins}},
@{n = "Secondary DNS" ; e = {$sdnswins}},
@{n = "Nic Name" ; e = {$name_nic}},
@{n = "VM Name" ; e = {$vmname}},
@{n = "IP policy" ; e = {$ip_policy}},
@{n = "Port Group" ; e = {$port_group}},
@{n = "MAC" ; e = {$mac}})
$get_details | Export-Csv c:\E1000_upgrade\Nic_details.csv
Write-Host "The VM name $vmname"
Write-Host "The VM NIC name $name_adapter"
write-host "physical nic name $name_nic"
Write-Host "The VM name $mac"
Write-Host "The Prod IP $ipaddr"
Write-Host "The Subnet $subnet"
Write-Host "The Gateway $gateway"
Write-Host "The Primery DNS $pdnswins"
Write-Host "The Secondary DNS $sdnswins"
Write-Host "The Secondary DNS $port_group"
Write-Host "the nic policy is $ip_policy"
Disconnect-VIServer $global:DefaultVIServers -Confirm:$false
}}}}}