PowerShell stuph...: Difference between revisions

From munkjensen.net/wiki
(Created page with " == Scripts i (ab)use == == Config NIC as DHCP Client == <pre>$IPType = "IPv4" $adapter = Get-NetAdapter | ? {$_.Status -eq "up"} $interface = $adapter | Get-NetIPInterface...")
 
No edit summary
Line 1: Line 1:


== Scripts i (ab)use ==
= Scripts i (ab)use =


 
==== Config NIC as DHCP Client ====
== Config NIC as DHCP Client ==


<pre>$IPType = "IPv4"
<pre>$IPType = "IPv4"

Revision as of 12:33, 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
}