PowerShell stuph...: Difference between revisions

From munkjensen.net/wiki
No edit summary
mNo edit summary
Line 1: Line 1:
= Scripts i (ab)use =
= Scripts i (ab)use =
 
<blockquote>
<div class="toccolours mw-collapsible mw-collapsed">
<div class="toccolours mw-collapsible mw-collapsed">
==== Config NIC as DHCP Client ====
==== Config NIC as DHCP Client ====
Line 24: Line 23:
</div>
</div>
</div>
</div>
 
</blockquote>
 
[[Category:Windows]]
[[Category:Windows]]

Revision as of 12:39, 16 November 2016

Scripts i (ab)use

Config NIC as DHCP Client

$IPType = "IPv4"
$adapter = Get-NetAdapter | ? {$_.Status -eq "up"}
$interface = $adapter | Get-NetIPInterface -AddressFamily $IPType

If ($interface.Dhcp -eq "Disabled") {
    # Remove existing gateway
    If (($interface | Get-NetIPConfiguration).Ipv4DefaultGateway) {
        $interface | Remove-NetRoute -Confirm:$false
    }

    # Enable DHCP
    $interface | Set-NetIPInterface -DHCP Enabled

    # Configure the  DNS Servers automatically
    $interface | Set-DnsClientServerAddress -ResetServerAddresses
}