# PowerShell - zdalna zmiana ustawień adresów DNS

Czasami trzeba szybko zmienić adresy serwerów DNS na wielu maszynach jednocześnie. Zamiast robić to ręcznie, można użyć prostego skryptu PowerShell.

blog

09 Feb 2016 pl

![PowerShell - zdalna zmiana ustawień adresów DNS](/wp-content/uploads/2015/07/PowerShell-Automating-Administration.jpg)

Czasami trzeba szybko zmienić adresy serwerów DNS na wielu maszynach jednocześnie. Zamiast robić to ręcznie, można użyć prostego skryptu w **PowerShellu**.

Poniższa funkcja łączy się z wybranym komputerem, znajduje kartę sieciową po nazwie interfejsu i ustawia nowe **serwery DNS** za pomocą `Set-DnsClientServerAddress`.

```powershell
function Set-DnsServerIpAddress {
    param(
        [string] $ComputerName,
        [string] $NicName,
        [string[]] $IpAddresses
    )

    if (Test-Connection -ComputerName $ComputerName -Count 2 -Quiet) {
        Invoke-Command -ComputerName $ComputerName -ScriptBlock {
            param($ComputerName, $NicName, $IpAddresses)

            Write-Host "Setting on $ComputerName on interface $NicName a new set of DNS Servers $IpAddresses"
            Set-DnsClientServerAddress -InterfaceAlias $NicName -ServerAddresses $IpAddresses
        } -ArgumentList $ComputerName, $NicName, $IpAddresses
    } else {
        Write-Host "Can't access $ComputerName. Computer is not online."
    }
}
```

Użycie skryptu jest proste: podaj nazwę komputera, nazwę karty sieciowej lub wzorzec nazwy oraz listę adresów DNS, które mają zostać ustawione.

```powershell
# $ServerName can be set as needed.
# Service is the name of the network card. Wildcards are supported.
# IpAddresses are passed as an array.
Set-DnsServerIpAddress -ComputerName $ServerName -NicName "Service*" -IpAddresses '8.8.8.8', '8.8.4.4', '8.8.8.1'
```

## Powiązane projekty

Projekty powiązane z tagami, kategoriami i treścią tego wpisu.

[Wszystkie projekty](/projekty/)

Trwa dopasowywanie projektów...

[Powrót do bloga](/blog/)

## Powiązane wpisy

- [Powershell – Change DNS IP Addresses remotely](/blog/powershell-change-dns-ip-addresses-remotely/)
- [PowerBGInfo 2.x: support-ready Windows backgrounds from PowerShell](/blog/powerbginfo-support-ready-windows-backgrounds/)
- [Check an API write after a PowerShell timeout](/blog/verify-uncertain-api-outcomes-powershell/)

<!-- PowerForge markdown artifact sha256:4CCAE1683CEA327FA4E0B3F3C57BC8483A1EDDC6AB9C8DF6D1E4A82ECB1B41DC -->
