Automate Network tasks like a pro w/ Windows Server 2019 & PowerShell

Hello and welcome my very first Windows blog tutorial. Today, we will be running a small but effective Networking script I wrote. So, lets get to it.

Run Each line individually. Highlight a string and then press F8.
# List IP addresses

Each on of these commands will look for the internal ipv4 and ipv6. Each on provides a little difference in detail.

Now lets look at how to retrieve adapter information. We will need to run the script first.

cd into the file containing folder , you will need to save it in ISE if haven’t done so already
Get-CimInstance -Class Win32_NetworkAdapter -ComputerName .

This will return all types of valuable information depending on what you’re troubleshooting.

Lets take a look at DHCP servers while are here. If you are unsre what a DHCP server is , it is a server that gives out IP addresses to other devices on the network. When we flush or dns then release/renew , this gives us a new dynamic or dhcp lease. Lets take a look at the adapters.

# Locate, Retrieve, Enable
Get-CimInstance -Class Win32_NetworkAdapterConfiguration -Filter "DHCPEnabled=$true"
# Release and Renew the fancy way by specifying adapters
Get-CimInstance -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled=$true and DHCPEnabled=$true" |
Where-Object {$_.DHCPServer -contains ''} |
ForEach-Object -Process {$_.ReleaseDHCPLease()}

We have now released and renewed and doublechecked all our adpaters on the network. These type of automated scripts can become even more complex and get a lot more done in one shot. Imaging have a network with 10 Domains and 1000 clients on each?! Automating PowerShell scripting can knockout all of that work in a matter of seconds. Thanks Microsoft!!!

Now lets go over two more commands and are done.

# Shared Folder example only
(Get-CimInstance -List |
Where-Object {$_.Name -eq 'Win32_Share'}).Create(
'C:\temp','TempShare',0,25,'test share of the temp folder'

There are many ways to make a shared folder, this is probably the most accurate expression of the a professionals use case an it’s another way of automating the process. We are essentially mapping a folder from one client to a server , server to server, client to client , the possibilities are endless. And again, having a ton of clients on a network can be a lot of work. Mapping 25 Devices with one flick a keyboard sounds like a better option. I think your starting to catch my drift.

After all of that we have only one thing left to do. We just did quite a bit of on our network. Transferred files , setup DHCP, Uncovered our adapters, lets go easy with one last command. Ping!

Get-CimInstance -Class Win32_PingStatus -Filter "Address='xxx.x.x.x'"

Great Job! Thank you to those that made it through this article, it may not be the most interesting thing but I think anyone can make Networking fun.

Come back for more content, Thanks!

V, theadaptation

My name is Vincent. I’m a security & tech researcher Website: Patreon: