Powercli: Vmware uzerindeki sunucularin dnsserverdaki kayitlarini kontrol etmek

Bu script vmware uzerindeki sanal sunucularin hostname ve ip adreslerini getirerek dns sunucu uzerinden bu sunucularin kayitlari varmi yada dogru mu diye kontrol edebiliriz. Ben sonuclari ayrica bir mysql servera gonderiyorum. Bunu bir web portal uzerinden kolayca gormemizi sagliyor. Yakin zamanda tum projeyi acik kaynak kod olarak paylasmayi hedefliyorum.

 

Import-Module -Name DnsServer
#Get-WindowsFeature -Name RSAT-DNS-Server

. C:\Scripts\Vcenter-Connection.ps1

clear

#connect the library MySql.Data.dll
. C:\Scripts\SQL-Connection.ps1

$dnsServerName = “ozgur.local”

#Table Name
$tableName = “vmware.dnszones”

## Remove old values
$query = “TRUNCATE $tableName”
Invoke-MySQLQuery -ComputerName $mysqlServer -Credential $credential -Database $database -Query $query

$zones = Get-DnsServerZone -ComputerName $dnsServerName | WHERE ZoneName -NotLike “*.in-addr.arpa*”
foreach($zone in $zones){

$ZoneName = $zone.ZoneName
$ZoneType = $zone.ZoneType

$query = “INSERT INTO vmware.dnszones (ZoneName,ZoneType) VALUES ( ‘$ZoneName’,’$ZoneType’)”

Invoke-MySQLQuery -Query $query -ComputerName $mysqlServer -Credential $credential

}

## Remove old values

#Table Name
$tableName = “vmware.zonedetails”

## Remove old values
$query = “TRUNCATE $tableName”
Invoke-MySQLQuery -ComputerName $mysqlServer -Credential $credential -Database $database -Query $query

 

foreach($zone in $zones){

$ZoneDetails = Get-DnsServerResourceRecord -ZoneName $($zone.ZoneName) -RRType A -ComputerName $dnsServerName

foreach($ZoneDetail in $ZoneDetails){

$ZoneName = $zone.ZoneName
$HostName = $ZoneDetail.HostName
$RecordClass = $ZoneDetail.RecordClass
$IPAddressToString = $ZoneDetail.RecordData.IPv4Address.IPAddressToString
$RecordType = $ZoneDetail.RecordType

$query = “INSERT INTO vmware.zonedetails (ZoneName,HostName,RecordClass,IPAddressToString,RecordType) VALUES ( ‘$ZoneName’,’$HostName’,’$RecordClass’,’$IPAddressToString’,’$RecordType’)”

Invoke-MySQLQuery -Query $query -ComputerName $mysqlServer -Credential $credential

}

}

Disconnect-VIServer -Server * -Confirm:$false

Join the ConversationLeave a reply

Your email address will not be published. Required fields are marked *

Comment*

Name*

Website