# Kod uaktywnia funkcj usuwania rekordw dla wszystkich stref zintegrowanych z usug Active Directory

use Win32::OLE;
$Win32::OLE::Warn = 3;

# ------ KONFIGURACJA SKRYPTU ------
$strServer = '<NazwaSerwera>';
$intScavengingInterval = '<LiczbaMinutOczyszczania>';
$intNoRefreshInterval = '<LiczbaMinutBezOdwieania>';
$intRefreshInterval = '<LiczbaMinutZOdwieaniem>';
# ------ KONIEC KONFIGURACJI ---------
$objDNS = Win32::OLE->GetObject('winMgmts:\\\\' . $strServer . '\\root\\MicrosoftDNS');
$objDNSServer = $objDNS->Get('MicrosoftDNS_Server.Name="."');

$objDNSServer->{ScavengingInterval} = $intScavengingInterval;
$objDNSServer->{DefaultNoRefreshInterval} = $intNoRefreshInterval;
$objDNSServer->{DefaultRefreshInterval} = $intRefreshInterval;
$objDNSServer->{DefaultAgingState} = 1;
$objDNSServer->Put_;
print "Dla serwera skonfigurowano ustawienia funkcji usuwania rekordw\n";

$objZones = $objDNS->ExecQuery('Select * from MicrosoftDNS_Zone ' . 'Where DnsServerName = \'' . $objDNSServer->Name . '\'' . '  And DsIntegrated = TRUE');
print "Skonfigurowano nastpujce strefy zintegrowane z usug Active Directory: \n";
foreach $objZone (in $objZones) {
   print ' ', $objZone->Name, ' Czas istnienia: ', $objZone->Aging, "\n";
   $objZone->{Aging} = 1;
   $objZone->Put_;
}
