How to clean up old DHCP server’s entry in a domain via PowerShell and netsh command

It’s very easy to forget old server entries and it may cause an issue in your network.  Sometimes system/network admin wait for approval process or schedule to clean up or just simply don’t know how to.  Whatever your reason is, this should be done to keep your network healthy from any unknown issues.  Here are some ways to clean up, I have listed PowerShell, Netsh and via GUI.

Via PowerShell:

To see list of all DHCP server run PowerShell command:

PS C:\>Get-DhcpServerInDC

To remove it:

You have to be domain or enterprise admin to remove it otherwise, you will get error

PS C:\>Remove-DhcpServerInDC –DnsName YourDHCPserver –IPAddress

This is without error: if you have run as admin

To add it:

You have to be domain or enterprise admin to remove it otherwise, you will get error

PS C:\> Add-DhcpServerInDC –DnsName YourDHCPserver –IPAddress

Using netsh commands

To the list of commands: netsh dhcp list

To add:

Netsh dhcp add server NameOfYourDHCPServer IP address

To delete:

Dhcp delete server NameOfYourServer IP address

Via GUI:

To add:
open your DHCP server, right-click, and select add

To Remove:
open your DHCP server, right-click and select Manage authorized servers …
Then just remove HDCP server that’s no longer in use

That’s it



How to redirect HTTP to HTTPS in IIS

Redirect are very common for web servers for most if not all websites these days.  This post I am using the URL Rewrite, if your server does not have already you need to download URL Rewrite extension which works With IIS 7, IIS 7.5, IIS 8, IIS 8.5, IIS 10.  Note.  If you already have the URL Rewrite you can skip to the section Adding Redirect Rule

Installation of URL Rewrite:

You can download directly from this link: https://www.iis.net/downloads/microsoft/url-rewrite

If you already have the Web Platform Installer, you can double click and find it there, under your web server>Sites>Select site>on the right-side panel you will see Management section

To start the installation double click on the URL Rewrite and click Install

Read the terms then click on I Accept

If everything goes well you should see, successfully installed, click Finish
you should see the URL Rewrite, if you don’t close the IIS Manager and re-open it.

Adding Redirect Rule:

Double click on the URL Rewrite for the site you want to redirect

Add your rules here, which fits your needs you may need more than one rules

I am going to create a rule to redirect HTTP to HTTPS:

Click Add Rules(s)
Then click on Blank rule (for Inbound rules)

Fill in the Name and other options shown in the screenshot, then expand the Conditions and click Add

This condition will check if user type’s https, then this rule will be ignored, so it avoids the loop

Nothing set on the server variables, unless you needed in some special case, you can add it, Next, we want to set up the redirect
https://{HTTP_HOST}/{R:1}

https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference

Your Rule should look something like this if you open your web.config file:
        <rewrite>
            <rules>
                <rule name=”http to https redirect” stopProcessing=”true”>
                    <match url=”(.*)” />
                    <conditions logicalGrouping=”MatchAny”>
                        <add input=”{HTTPS}” pattern=”^OFF$” />
                    </conditions>
                    <action type=”Redirect” url=”https://{HTTP_HOST}/{R:1}” />
                </rule>
            </rules>
        </rewrite>

If you have issues make sure to check following:

  • Make sure your webserver firewall ports 80 and 443 are opened
  • You may need to restart the IIS service for rule to take effect, also make your local cache is cleared for your browser.
  • Double-check the pattern of your rule make sure it’s correctly typed, not a typo

That’s it



How to delete old VM from Hyper-V Cluster

Hyper-V cluster is a very common business network uses, which allows system admin to do system updates, without having any downtime. There are times when VM (Virtual Machine) are created for a test or just got upgraded and left to be deleted later on. Cleaning up old VM will free up the storage space. In this post I will have steps on deleting VM from Hyper-V cluster, before deleting, check the location of the VM because deleting from the Cluster server, will not free up the storage, you will need to delete it manually. You can see the location of the VM by going to settings of the VM and select the Disk, it will display full path where your VM disk is stored.

Open Failover Cluster Manager, then click on Roles, you should see list of VM’s, select the one you want to delete, then right on it and select Remove.

You will get confirmation message, make sure it’s the correct VM, then click Yes, The VM will be removed from the Cluster.

Then go to Hyper-V host where VM was running from, so you can remove from list

Confirmation are you sure you want to delete, if it’s correct VM you are deleting click Delete.

Now the VM is deleted from Cluster and remove from Hyper-V host, it’s time to delete the VM disk, by going to the location you looked at before you deleted the VM. That should give you back the storage space. That’s it, you get an error check the windows log or application log, it will give you more info.



How to restore deleted VM from Cluster

By mistaken you have deleted good VM and if you still have the VM disk, you can still bring it back online. As long as VM disk is not deleted from the Hyper-V it would be a very easy restore. Option 1 if you have not deleted VM from Hyper-V if you have deleted from Hyper-V follow option 2 after selecting VM from the Cluster Role.

Option 1

Open Failover Cluster Manager

Right click on the Roles>choose Configure Role …


Then you may get this default message: click next

Select the Virtual Machine, then click Next

Then you will see your deleted VM here: select it and click Next

If you don’t see the VM go to Option 2

Confirmation, Click Next

If everything goes well you should see success message with summary, if you want to see details click on View Report or click Finish.

Options 2

If you deleted VM and removed the Hyper-V host then you not see here, then you will need to add VM as new and use the same Disk

Adding new VM to Cluster with existing disk

Select the Cluster node (Hyper-V host), then click ok

Then you may see the New Virtual Machine Wizard, click Next

Then the VM to whatever you like, then click Next

Select the Generation of the VM:

Then set Memory and click Next

Select networking from list, then click Next

At this screen you will select the use an existing virtual hard disk, then click Next

You should see the Summary of new VM, if everything is good, click Finish

If everything goes well, you should see the Success message, click View Report for details or click Finish

That’s it, you should see your recovered VM back in the Cluster



Clean up dead domain controller Windows 2012 R2

Many small companies have a small network and they have limited IT staff or manage IT services to take care of their network. I have seen old network devices, application, plan for cleaning up but it’s been forgotten which creates a problem in the future. The worse part is when the company doesn’t have a strict policy, budget or just don’t want to change, so things just build up until it reaches to a dead end. The domain controller is very important part of the network, if it keeps up to date and removed the old controller, then it could cause major issues. Here is how to clean up an old domain controller. Make sure you have a good backup and primary domain controller is a good healthy state.

Open Active Directory Users and Computers

Select domain>Domain Controllers>on right side it will list your domain controllers on the right side panel. You will see DC Type GC (Global Catalog) and Read-Only, GC Domain Controller.


Right click on the domain controller you want to delete, select delete. You will see confirmation screen select Yes

Select the options to clean up when your old domain controller deletes

Then it’s going to have confirmation and list of operations, based on your selection, once check then click OK

If your domain controller is part of GC, you will see: “This Active Directory Domain Controller is a global catalog“, before you click Yes, make sure you have at least one Global Catalog domain controller.

That will remove your old domain controller, then clean up any other metadata left around. If you have multi sites, open Active Directory Sites and Services: Sites>Delete old site

You will get Confirm Subtree Deletion message, click yes if nothing else is on that site

Then check your primary domain controller health and logs, to make sure everything is fine. Keep your eyes open on any application/services that may have any issues, it should not, but just in case. That’s it