Network Commands in PowerShell

Need something similar to Ipconfig in PowerShell, try these commands.

Get Network Adapter Details in PowerShell.

Get-NetAdapter | ft ifname,ifdesc,ifIndex,MacAddress,status,LinkSpeed,LinkSpeed -AutoSize

Use Get-NetAdapter |FL * for all Details.

Get IP Address Details in PowerShell

Get-NetIPConfiguration| Sort InterfaceIndex | ft InterfaceAlias,InterfaceIndex,InterfaceDescription,AllIPAddresses -AutoSize

OR

Get-NetIPAddress | Sort InterfaceIndex | FT InterfaceIndex, InterfaceAlias, AddressFamily, IPAddress, PrefixLength -Autosize

Use Get-NetIPConfiguration | fl * for all details.

Get Client DNS Settings in PowerShell.

Get-DnsClient | sort interfaceIndex | ft interfaceIndex,InterfaceAlias,ConnectionSpecificSuffix,SuffixSearchList,RegisterThisConnectionsAddress -AutoSize

Get-DnsClientServerAddress |sort interfaceindex | ft InterfaceIndex,InterfaceAlias,ServerAddresses,EnabledState

The Basics of PowerShell

Step #1 – Modules

Modules are a set of related Windows PowerShell functions, many roles/functions have specific modules which get installed when the remote administrative tools are installed for a product such as Active Directory, Group Policy, Hyper-V, Failover Clustering… other products have Powershell modules included in their installation such as SQL, Exchange while others are downloadable such as Azure.

Before Windows 8/2012+ you needed to perform “import-module” to add modules to the current session.

To get the “Available Modules” which are essentially the PowerShell modules installed on the machine, the following can be run.

Get-Module -ListAvailable

To import all available modules you can Right Click PowerShell from explorer.

Import-Modules

or run the following from within PowerShell.

Get-Module -ListAvailible | Import-Module

 Step #2 – What to run

PowerShell uses a verb-noun pair for the names of cmdlets and for their derived Microsoft .NET Framework classes. The verb part of the name identifies the action that the cmdlet performs. The noun part of the name identifies the entity on which the action is performed.

Microsoft has an Approved Verbs for Windows PowerShell Commands list available.

Use “get-command” to display the available Cmdlets, Functions and Aliases available to be run. You can use a wildcard search parameters to find the appropriate verb/noun of the cmdlet you will want to run.

For a starting point the following would show various cmdlets that could be run to gather information on the computers network settings.

get-command get-net*

Notice the “GET” command was used for getting information.

As an alternative to the get-command cmdlet, “show-command” in Windows 8/2012+ can be used, or the “ISE” Integrated Scripting Environment.

Step #3 – Find the appropriate properties to output

Using the “Get-Member” or “GM” cmdlet you can easily find the output properties of a cmdlet. Select the appropriate properties to output.

get-member

Using a cmdlet such as get-help can aide in finding examples of what to run and more details about the cmdlet.

Note: Check out the “update help” Article for details about keeping your help files up-to-date (ensure you are running update-help from an elevated Powershell Window.)

Get-Help Get-NetAdapter

get-help

Using a simple command such as the following would export my chosen network adapter settings to the screen –>

 Get-NetAdapter

Notice by default it selected only a few of the available properties.

get-netadapter

Step #4 – Formatting the output

In PowerShell you can easily change how you can view it on the screen using the “format-table” or “format list” cmdlets.

Notice the “aliases” used — FT for Format-Table and FL for Format-List.

The following could be used to change the view of the data into a list format or table format.

Get-NetAdapter | FL name,status,linkspeed

Format Table

For simplicity to find all the properties available for output the following could also be used.

Get-NetAdapter | FL *

format-list

Step #5 (coming coon) filtering the output

 

Powershell Help files – Keeping them up-to-date, automated and available offline.

Keeping your Powershell Help files up-to-date is a relatively easy task.

Run the “update-help” cmdlet.

The Update-Help cmdlet downloads the newest help files for Windows PowerShell modules and installs them on your computer. “–Force” Overrides the once-per-day limitation, version checking, and the 1 GB per module limit.

Note: You *may* need to be elevated to an Administrator to update the “Core” PowerShell Modules as only members of the Administrators group on the computer can download help for the for modules in the $pshome\Modules directory.

Individual modules can be updated by specifying the module parameter “Update-Help -Module ServerManager, Azure” (notice the comma separation if multiple modules are required).

Automating the Task:

Update of help can be automated using a scheduled job to ensure the latest version of the help files exist:

Register-ScheduledJob -Name UpdateHelpJob -Credential YourDomain\AUser -ScriptBlock {Update-Help} -Trigger (New-JobTrigger -Daily -At “12 AM”)

Offline Help:

For offline computers the “save-help” cmdlet can be used to download the help files. This can be done from an Internet-connected client computer, without installing the module or the Server role on the local computer.
Saving the Help file (without having the module installed) Example–>

$module = Invoke-Command -ComputerName RemoteServer -ScriptBlock { Get-Module -Name Hyper-V -ListAvailable }
Save-Help -Module $m -DestinationPath C:\HelpFolder

Copy the files to a flashdrive (or use a remote share) and update the local machine(s) –>

Update-Help –Module Hyper-V –SourcePath D:\FlashDrive\HelpFolder