LoginSignup
0
0

More than 5 years have passed since last update.

固定IP設定

Posted at

テキストファイルから対象のPCを検索して
対応するIPアドレスを設定する

の内容
pcname ip


test1,10.189.192.3
test2,1.1.1.1
DESKTOP-JL63VBE,192.168.0.200

<設定するパソコンのホスト名をテキストファイルから検索してIPを表示>
$array1=Get-Content .\ip.txt | Select-String $hname
$s=$array1 -split(",")
$n=@($s)
$n[1]
192.168.0.200

静的ip削除
Remove-NetIPAddress -InterfaceIndex 11 -IPAddress "192.168.0.100" -DefaultGateway "192.168.0.1"
※Get-NetAdapterで表示されたifIndex Statusの値

静的DNS削除
Set-DnsClientServerAddress -InterfaceIndex 11 -ResetServerAddresses

静的IP設定
New-NetIPAddress -InterfaceIndex 11 -IPAddress "192.168.0.200" -AddressFamily IPv4 -PrefixLength 24 -DefaultGateway "192.168.88.1"
静的DNS設定
Set-DnsClientServerAddress -InterfaceIndex 11 -ServerAddresses "192.168.88.1"


New-NetIPAddress -InterfaceIndex 11 -IPAddress $n[1] -AddressFamily IPv4 -PrefixLength 24 -DefaultGateway "192.168.0.1"

IPAddress : 192.168.0.200
InterfaceIndex : 11
InterfaceAlias : Wi-Fi
AddressFamily : IPv4
Type : Unicast
PrefixLength : 24
PrefixOrigin : Manual
SuffixOrigin : Manual
AddressState : Tentative
ValidLifetime : Infinite ([TimeSpan]::MaxValue)
PreferredLifetime : Infinite ([TimeSpan]::MaxValue)
SkipAsSource : False
PolicyStore : ActiveStore

IPAddress : 192.168.0.200
InterfaceIndex : 11
InterfaceAlias : Wi-Fi
AddressFamily : IPv4
Type : Unicast
PrefixLength : 24
PrefixOrigin : Manual
SuffixOrigin : Manual
AddressState : Invalid
ValidLifetime : Infinite ([TimeSpan]::MaxValue)
PreferredLifetime : Infinite ([TimeSpan]::MaxValue)
SkipAsSource : False
PolicyStore : PersistentStore

Set-DnsClientServerAddress -InterfaceIndex 11 -ServerAddresses "192.168.0.1"

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0