Friday, July 29, 2016

Reporting IP Addresses

Hi folks,

I would love to share with you helpful script which can be used to create report of the IP addresses configuration on Windows client or server. Of course ipconfig /all can be used. In this sense PowerShell script is very helpful as it talks to WMI and retrieves all the possible settings. Potentially they can be exported to CSV file by using Export-CSV cmdlet.

I found this this article to be extremely helpful as it covers multiple scenarios. In my cases I wanted to retrieve IP address and DNS related settings. Below is the code that I used them:

Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName . | Select-Object IPAddress,IPSubnet,DefaultIPGateway,*DNS*

I have got the following output:


Depending on the properties you are trying to retrieve, you can tweak properties as you desire.

There are couple of comments that would love to make about the output that I have got:



"Register this connection addresses in DNS" setting in GUI corresponds to the FullDNSRegistrationEnabled

"Use this connection's DNS suffix in DNS registration" corresponds to DomainDNSRegistrationEnabled

Tick box enabled corresponds to the True in output while check box disabled corresponds to False.


Enjoy!

What Subnets Are In My Site

Hi folks,

You have probably read about retrieving domain controller in the site where computer or server is located. You can read this post here. In that post I tried to

I have capitalized on this blog post from Microsoft which addresses generic situation when you try to retrieve information about AD subnets in ad generic AD site (with the default name).

In my scenario I was trying to understand which subnets are configured in the AD site where my computer (server) is located.

The script queries WMI for the value of the AD site name where computer is located and feeds it to the $SiteName variable. Then it queries domain controllers by using $SiteName as a variable in order to retrieve domain controllers located in the same AD site:


$siteName =  [System.DirectoryServices.ActiveDirectory.ActiveDirectorySite]::GetComputerSite().Name

$configNCDN = (Get-ADRootDSE).ConfigurationNamingContext

$siteContainerDN = (“CN=Sites,” + $configNCDN)

$siteDN = “CN=” + $siteName + “,” + $siteContainerDN

$siteObj = Get-ADObject -Identity $siteDN -properties “siteObjectBL”, “description”, “location”

foreach ($subnetDN in $siteObj.siteObjectBL) {

    Get-ADObject -Identity $subnetDN -properties “siteObject”, “description”, “location” |select Name,SiteObject

}

I hope you find it helpful.

Enjoy