# Kod zmienia nazw komputera. Jeli w domenie istnieje konto
# komputera, NIE modyfikuje go.
use Win32::OLE;
$Win32::OLE::Warn = 3;

# ------ KONFIGURACJA SKRYPTU ------
$strComputer = '<AktualnaNazwaSerwera>';
$strNewName = '<NowaNazwaSerwera>';
# ------ KONIEC KONFIGURACJI ---------
use constant HKLM => 0x80000002;
$strKeyPath = 'System\\CurrentControlSet\\Control\\ComputerName\\ComputerName';
$objReg = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\default:StdRegProv');
$intRC = $objReg->SetStringValue(HKLM, $strKeyPath, 'ComputerName', $strNewName);
if ($intRC != 0) {
    print 'Bd ustawienia wartoci wpisu ComputerName: ' . $intRC, "\n";
}
else {
    print "Dla wpisu ComputerName ustawiono warto $strNewName\n";
}

$strKeyPath = 'System\\CurrentControlSet\\Services\\Tcpip\\Parameters';
$intRC = $objReg->SetStringValue(HKLM, $strKeyPath, 'NV Hostname', $strNewName);
if ($intRC != 0) {
    print 'Bd ustawienia wartoci wpisu NV Hostname: ' . $intRC, "\n";
}
else {
    print "Dla wpisu NV Hostname ustawiono warto $strNewName\n";
}

print "Ponowne uruchamianie systemu...\n";
$objWMI = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2');
foreach my $objOS (@{$objWMI->InstancesOf('Win32_OperatingSystem')}) {
    $objOS->Reboot();
}
