IPAM 2016 in PowerShell

I recently got asked to help out to get IPAM installed and configured in our environment.
Now that’s not really hard to do, but I thought I’d do it all through my favourite tool: PowerShell.

What is IPAM

Let’s go back a step quickly and answer the obvious question:

What is IPAM and why do I need it

IPAM stands for IP Address Management and it’s a built-in feature for Windows Server since 2012 and up.
To quote Microsoft:

IPAM provides highly customizable administrative and monitoring capabilities for the IP address and DNS infrastructure on an Enterprise or Cloud Service Provider (CSP) network. You can monitor, audit, and manage servers running Dynamic Host Configuration Protocol (DHCP) and Domain Name System (DNS) by using IPAM.

Now there are a plethora of IPAM installation and configuration guides, but I noticed that while some of them touch on PowerShell cmdlets available, none of them actually seem to do the installation and configuration through PowerShell itself!

Give me the good stuff!

I’ve made a script which uses all the techniques the “manual” guides say are best practice, along with the IPAM troubleshooting guide to make sure all permissions work as a charm [don’t be fooled by the beta name, this still applies to 2016 server as well].

The entire script should be run region by region on the actual IPAM to be server, assuming it is domain joined and the person installing has all the required permissions to do so [as well as simple AD query permissions].

While the latest version can be found on my GitHub repo, I’ve added a copy here so you can start playing around ASAP!

Happy Scripting! 🙂

 

Facebooktwitterredditlinkedinmail

Finding remote registry entries with Remoting disabled…

I had run into a situation where I quickly needed to check registry entries for various machines, but PowerShell remoting had not properly been enabled for all of the machines [and was not allowed to be set up on short notice].

Since I needed to quickly obtain the information for various keys, I turned to Google for advice.

Local and Remote

Firstly I’ll define the registry keys I’d like to have information about:

So normally you can get the Local information using the following code:

If you want to obtain the information Remotely, try the following:

As you can see, I can’t just use the variables provided locally, but since I’m running an up-to-date version of PowerShell [v3+], I can using the Using scope modifier, as described here.

I’ve also quickly created a PSCustomObject to contain all the information I require, so I can output this in a clean way.

But what if Remoting is not enabled?

Have no fear, you can still use PowerShell to access the data you want, just through an alternative means.

In this situation, PowerShell can use the power of .NET to still get what it wants!
Do note that this does require the Remote Registry Service to be running on the machine.

Firstly, because of the way registry keys are interpreted through the .NET class, this means splitting up our $RegKey1 and $RegKey2 value into a $Hive [since both are in HKLM] and $Key values:

Using the Microsoft.Win32.RegistryKey class provided by .NET, you can open up a remote connection to a specific hive [LocalMachine, Users] on a remote machine  [you can see this method and other methods available to perform various tasks here].

Once you’ve defined the remote registry connection, you can start getting the information you require using the OpenSubKey and GetValue methods.

What does this look like as a final result:

Hopefuly this can help you in a situation where you just NEED to view remote registry entries, but PowerShell Remoting isn’t [fully] configured.

Happy scripting! 🙂

 

Facebooktwitterredditlinkedinmail

Script Dumpster: Find duplicate entries over multiple reports

Another day at the office..

Thanks to our friends who wrote the NotPetya worm, I received an email from our monitoring vendor to run reports to see if our machines are up-to-date on their patching.

Unfortunately their reporting tool doesn’t properly distinguish between Windows Server 2008 and Windows 2008 R2, as well as Windows 2012 and Windows 2012 R2.

Long story short,  I had to create 4 separate reports, telling me if I had or had not installed the proper KB item on each machine.

Because of this flaw I also had to join the reports and check the “Highlight Duplicates” option in Excel to see whether or not servers had their respective Hotfix installed (if the server had a duplicate entry, it meant that it didn’t have either the standard or R2 patch installed, meaning vulnerable).

Each report also came with a 3 row header with random junk that needed to be removed, so a simple Ctrl + A , Ctrl + C, Ctrl + V wouldn’t suffice.

PowerShell to the rescue!

I looked at the email from the vendor and went “Hell no, I’m not going to do that…” and opened up PowerShell ISE.

Having dumped the reports in the folder c:\Temp\NotPetya , I came up with the following script:

While the coding took a little bit longer, the execution was swift and perfect.

Geeks and Automation

 

Happy scripting! 🙂

Facebooktwitterredditlinkedinmail