qshinoの日記

Powershell関係と徒然なこと

Powershell IPアドレス変更

基本手順

1. Net Interface取得

1. 削除

2. 設定

 

コマンド

1. IF情報取得

 

    Get-NetIPInterface

 

ifIndexとalias一覧取得

 

2. 削除

Remove-NetIPAddress -InterfaceIndex <index>  -IPAddress "<Host-IP>" -DefaultGateway "<GW-IP>"

Set-DnsClientServerAddress -InterfaceIndex <index> -ResetServerAddresses

 

3. 設定

 

静的IPの例

1. 削除

Remove-NetIPAddress -InterfaceIndex 13 -IPAddress "192.168.88.88" -DefaultGateway "192.168.88.1"

 

Set-DnsClientServerAddress -InterfaceIndex 13 -ResetServerAddresses

 

2. 設定

# IPアドレス

New-NetIPAddress -InterfaceIndex 13 -IPAddress "192.168.88.88" -AddressFamily IPv4 -PrefixLength 24 -DefaultGateway "192.168.88.1"

#DNSサーバーアドレス

Set-DnsClientServerAddress -InterfaceIndex 13 -ServerAddresses "192.168.88.1"

 

 

DHCPの例

1.削除

Remove-NetIPAddress -InterfaceIndex 13 -DefaultGateway "172.16.64.1"

 

2.設定

Set-NetIPInterface -InterfaceIndex 13 -Dhcp Enabled

 

ネットワークアダプタの有効無効

無効化

Disable-NetAdapter -Name "名前"

有効化

Enable-NetAdapter -Name "名前"

 

 # 参考

 

http://qiita.com/hanakara_milk/items/1197ac9b91fa1fa3abab

下記のサイトが良く分かる。

http://qiita.com/hanakara_milk/items/1197ac9b91fa1fa3abab

あるいは、この辺り

https://www.upken.jp/kb/powershll-setipaddress.html

https://technet.microsoft.com/ja-jp/library/jj717268(v=ws.11).aspx

ホスト名取得としたら、

https://www.google.co.jp/amp/tech.guitarrapc.com/entry/2013/06/17/190601?amp=1

 

# 対応バージョン

 

Windows8.1以上

Windows Server 2012R2以上

 

# 未満の場合

 

Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter 'IPEnabled = True'

 

[System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() `
| ForEach-Object { $_.GetIPProperties() } `
| Select-Object -ExpandProperty 'UnicastAddresses';

 

# 参考

 

http://stackoverflow.com/questions/19529442/gather-ip-address-information

 

# netsh

 

## ipアドレス変更

 

netsh interface ip set address “アダプタ名” static address mask gateway

 

## dhcp設定

 

netsh interface ip set address “アダプタ名” dhcp

 

## 取得方法

 

netsh interface ip show config

 

netsh interface ip show addreses

 

netsh interface ip show compartments

 

# 参考

 

http://www.atmarkit.co.jp/ait/spv/1002/05/news097.html

 

http://zacodesign.net/blog/?p=1259

 

# さらなる調査

 

http://ameblo.jp/memomemoag0u3/entry-11741667885.html