Network_Set_StaticIP.ps1
|
function Network-SetStaticIP { $compName = (Read-Host -p "Enter computer name") $intName = (Read-Host -p "Enter interface name") $staticIp = (Read-Host -p "Enter static IP address") $subnetMask = (Read-Host -p "Enter subnet mask address") $gateway = (Read-Host -p "Enter default gateway address") $adapter = Get-CimInstance Win32_NetworkAdapterConfiguration -Computer $compName |Where-Object { $_.Description -match $intName} $adapter | Invoke-CimMethod -Name EnableStatic -Arguments @{IPAddress = $staticIp; SubnetMask = $subnetMask } $adapter | Invoke-CimMethod -Name SetGateways -Arguments @{DefaultIPGateway = $gateway; GatewayCostMetric = [UInt16] 1 } } |