IT 442: Windows Operating System
Network PowerShell Cmdlets
Introduction
- Windows Command Prompt – also known as CMD – is the original shell for the Microsoft DOS operating system.
- Windows PowerShell is the new Microsoft shell that combines the old CMD functionality with a new
scripting/cmdlet instruction set with built-in system administration functionality.
- PowerShell cmdlets allow users and administrators to automate complicated tasks with reusable scripts.
System administrators save significant time by automating administration tasks with PowerShell.
- PowerShell uses pipes to chain together cmdlets and share input/output data the same way as other shells, like bash in linux.
- PowerShell, the shell application Microsoft was introduced with Windows 7.
- One of the (many) neat functions of PowerShell is the ability to create aliases for different cmdlets
- In PowerShell, both ‘ls’ and ‘dir’ are an alias for the cmdlet ‘Get-ChildItem.’
- There isn’t any command left in CMD that isn’t in PowerShell, and PowerShell includes cmdlets for any
administration function you could need
- PowerShell knowledge can be a differentiator for employment or even a job requirement, so it’s a worthwhile skill to invest in.
Installing PowerShell on macOS
Ping devices locally or remotely: Test-NetConnection -ComputerName “Hostname or IP”
- Test-NetConnection -ComputerName “Hostname or IP”
- The Test-NetConnection cmdlet offers a number of ways to test network connectivity on the LAN and WAN.
- After running the command, computer will perform a ping to determine if network connectivity between the local device
and the target computer or domain exists.
Check connectivity based on port or service: Test-NetConnection “Hostname” -Port #
- Test-NetConnection “Hostname” -Port #
- Test-NetConnection cmdlet has the ability to test the connectivity between the local device and the target host by specifying a port number.
- This is extremely useful for testing services between devices and the ports they communicate on specifically.
Trace route communications: Test-NetConnection “Hostname” -traceroute
- Test-NetConnection “Hostname” -traceroute
- Performing a trace route to determine how many hops (or steps) a packet must go through to get from the source to its destination
is an important tool, as it allows you to see where the transmission is going, and more important, whether it was successful. If it wasn’t,
trace route will indicate where the packet failed along the path.
Obtain IP configuration details: Get-NetIPConfiguration
- Get-NetIPConfiguration
- Similar to the ipconfig command, the Get-NetIPConfiguration cmdlet provides a holistic view of the network
configuration(s) set on the network adapters of a computer.
- IP, DNS, and Gateway addresses are displayed and sorted by adapter name.
Perform DNS lookups: Resolve-DnsName -Name “Hostname”
- Get-NetIPConfiguration
- Similar to the ipconfig command, the Get-NetIPConfiguration cmdlet provides a holistic view of the network
configuration(s) set on the network adapters of a computer.
- IP, DNS, and Gateway addresses are displayed and sorted by adapter name.
View current TCP connections: Get-DnsClient, Set-DnsClientServer Address
- Get-DnsClient: This cmdlet lets you check the DNS client information for a device. It will indicate
what DNS server(s) are being used by the device to perform address resolutions as configured on multiple adapters
- Set-DnsClientServer Address: DnsClientServerAddress cmdlet allows for specified DNS servers to be added to the network configuration
Flush DNS cache: Clear-DnsClientCache
- Clear-DnsClientCache
- The DNS cache helps keep often used DNS resolution records stored locally on a device, allowing it to read that record
instead of performing a lookup every time a record is requested
- This helps speed up the already fast resolution process
Release and renew DHCP leases
- Invoke-Command -ComputerName -ScriptBlock {ipconfig /release}
- Invoke-Command -ComputerName -ScriptBlock {ipconfig /renew}
- This helps speed up the already fast resolution process
Disable and enable network adapters
- Disable-NetAdapter -Name “Adapter Name”
- Enable-NetAdapter -Name “Adapter Name”
- This helps speed up the already fast resolution process
Reference