Thursday, 21 March 2013

Windows Server 2012 Server Core–Playing with Network Card using PowerShell Part 1

Finding the InterfaceIndex or InterfaceAlias of the network adapters in the system
Get-NetIPInterface
This will list all the Network cards with their InterfaceIndex, Interface lias, AddressFamily, NlMtu in Bytes, InterfaceMetric, DHCP status, ConnectionState and PolicyStore in that order.
To view more details about a particular network card use the following command
Get-NetIPInterface –InterfaceAlias <InterfaceAlias as String>                              or Get-NetIPInterface –InterfaceIndex <InterfaceIndex as UInt32>


Another command that you can use for this purpose is the following one
Get-NetIPConfiguration
Issuing this will command will give you the details of the IP Network Interfaces as shown below


If you want to get the details of a particular interface use the following command
Get-NetIPConfiguration –InterfaceAlias <InterfaceAlias as String>
                       or
Get-NetIPConfiguration –InterfaceIndex <InterfaceIndex as UInt32>
[Note: You can use any of these commands to find the InterfaceAlias or InterfaceIndex for the commands below and for commands in Part 2 of this post]
To view the status and properties of the network adapter
Get-NetAdapter
This will list the Name, InterfaceDescriptuion, InterfaceIndex, Status, MAC Address and Speed of all the visible network adapters in the system.
If you want to view the status of the hidden adapters also, use the following command
Get-NetAdapter –IncludeHidden
To disable a network adapter First find the InterfaceAlias using the “Get-NetIPInterface” command or InterfaceDescription using “Get-NetAdapter” of the desired interface. Now use the following command
Disable-NetAdapter -Name <InterfaceAlias>
                                              or
Disable-NetAdapter -InterfaceDescription < InterfaceDescription>
To disable a network adapter without asking for confirmation, use the following command
Disable-NetAdapter -Name <InterfaceAlias> -Confirm:$false
                          or
Disable-NetAdapter -InterfaceDescription < InterfaceDescription> -Confirm:$false
To enable a network adapter First find the InterfaceAlias using the “Get-NetIPInterface” command or InterfaceDescription using “Get-NetAdapter” of the desired interface. Now use the following command
Enable-NetAdapter -Name <InterfaceAlias>
                           or
Enable-NetAdapter -InterfaceDescription < InterfaceDescription>
To disable IPV6 in a network adapter First find the InterfaceAlias using the “Get-NetIPInterface” command or InterfaceDescription using “Get-NetAdapter” of the desired interface. Now use the following command
Set-NetAdapterBinding -Name <InterfaceAlias> -ComponentID ms_tcpip6 -Enabled $false
                                            or
Set-NetAdapterBinding -InterfaceDescription < InterfaceDescription> -ComponentID ms_tcpip6 -Enabled $false
Before Disabling IPv6
  After Disabling IPv6
Setting IPv4 address to a network card First find the InterfaceAlias or InterfaceIndex using the “Get-NetIPInterface” of the desired interface. Now to set the IP address, Subnet mask and default gateway for the desired network card please use any of the following command.
New-NetIPAddress –InterfaceIndex <InterfaceIndex as UInt32> –IPAddress <IPAddress as String> –PrefixLength < PrefixLength as Byte> –DefaultGateway < DefaultGateway as String>
                                                        or
New-NetIPAddress –InterfaceAlias <InterfaceAlias as String> –IPAddress <IPAddress as String> –PrefixLength < PrefixLength as Byte> –DefaultGateway < DefaultGateway as String>

   

No comments:

Post a Comment