Last active
August 29, 2015 14:12
-
-
Save ooltcloud/26d5ed5e4259faec029a to your computer and use it in GitHub Desktop.
デバイス名指定でネットワークアドレスを設定する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#---------------------------------------------------------------------- | |
# デバイス名指定でネットワークアドレスを設定する | |
#---------------------------------------------------------------------- | |
# (-)デバイス名からネットワーク名を求める | |
Function getNicName($deviceName) { | |
$na = Get-WmiObject Win32_NetworkAdapter | ? {$_.Name -eq $deviceName} | |
$na.NetConnectionID | |
} | |
# (+)デバイス名指定で静的IPアドレスを設定する | |
Function SetStaticIP($deviceName, $newIP, $newSubnetMask, $newGatewayIP, $gatewayMetric) { | |
$nicName = getNicName $deviceName | |
netsh interface ip set address $nicName static $newIP $newSubnetMask $newGatewayIP $gatewayMetric | |
} | |
# (+)デバイス名指定で静的IPアドレスを追加する | |
Function AddStaticIP($deviceName, $newIP, $newSubnetMask, $newGatewayIP, $gatewayMetric) { | |
$nicName = getNicName $deviceName | |
netsh interface ip add address $nicName $newIP $newSubnetMask $newGatewayIP $gatewayMetric | |
} | |
# (+)デバイス名指定でDHCPを設定する | |
Function SetDhcp($deviceName, $newIP, $newSubnetMask, $newGatewayIP) { | |
$nicName = getNicName $deviceName | |
netsh interface ip set address $nicName dhcp | |
} | |
# (+)デバイス名指定でネッワーク名を設定する | |
Function SetNicName($deviceName, $newName) { | |
$nicName = getNicName $deviceName | |
netsh interface set interface name="$nicName" newname="$newName" | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#---------------------------------------------------------------------- | |
# 使い方 | |
#---------------------------------------------------------------------- | |
# 1つめの静的IPとして 192.168.0.1/24、gw:192.168.0.254 を設定 | |
SetStaticIP "Hyper-V 仮想イーサネット アダプター #0" 192.168.0.1 255.255.255.0 192.168.0.254 | |
# 2つめの静的IPとして 192.168.1.1/24、gw:192.168.1.254,メトリック10 を設定 | |
AddStaticIP "Hyper-V 仮想イーサネット アダプター #0" 192.168.1.1 255.255.255.0 192.168.1.254 10 | |
# DHCP に戻す | |
SetDhcp "Hyper-V 仮想イーサネット アダプター #0" | |
# ネットワーク名を 「仮想イーサネット」 にする | |
SetNicName "Hyper-V 仮想イーサネット アダプター #0" "仮想イーサネット" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment