Scripting PowerShell DNS with WMI

PowerShell – Scripting DNS with WMI

Our mission on this page is to install the Root\MicrosoftDNS namespace.

 PowerShell WMI DNS Topics

 ♣

Preparation With PowerShell’s Get-Help

Before we use PowerShell’s DNS, let us investigate the master cmdlet Get-WmiObject.  In particular, we need to understand the syntax of parameters such as -Class and -ComputerName.  Incidentally, you can use the alias gwmi instead of of Get-WmiObject.

# Help with PowerShell WMI object:
Get-Help Get-WmiObject

Note 1: If you prefer to see examples append -full, thus: help Get-WmiObject -full

How to Install Root\MicrosoftDNS

CIM means Common Information Model, with WMI, mostly we connect to Root\Cimv2.  However there are other CIM providers, for example Root\MicrosoftDNS.

The problem.  If we enumerate the CIM namespaces, we see that MicrosoftDNS is not listed BEFORE our procedure below.

# PowerShell DNS Provider
Clear-Host
$RootName = Get-WmiObject -namespace "root" -class __NAMESPACE `
| Sort-Object "Name"
Foreach ($Provider in $RootName) {
$Provider.name |Out-File -filePath provider.txt -append

 Before

After Procedure Below

aspnet
CIMV2
Cli
DEFAULT
directory
Microsoft
MicrosoftActiveDirectory

MicrosoftIISv2
MicrosoftNLB
MSAPPS11
MSAPPS12
MSCluster
perfmon
Policy
RSOP
SECURITY
snmp
subscription
vm
WMI

aspnet
CIMV2
Cli
DEFAULT
directory
Microsoft
MicrosoftActiveDirectory
MicrosoftDNS
MicrosoftIISv2
MicrosoftNLB
MSAPPS11
MSAPPS12
MSCluster
perfmon
Policy
RSOP
SECURITY
snmp
subscription
vm
WMI

Windows Server appears to have the necessary files, dnsschema.mof and dnsprov.dll, it’s just they are not registered by default.

Guy Recommends:  A Free Trial of the Network Performance Monitor (NPM)Review of Orion NPM v11.5 v11.5

SolarWinds’ Network Performance Monitor will help you discover what’s happening on your network.  This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.

What I like best is the way NPM suggests solutions to network problems.  Its also has the ability to monitor the health of individual VMware virtual machines.  If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.

Download a free trial of Solarwinds’ Network Performance Monitor

Agony and Ecstasy of Dnsprov Download

The agony would be if you went ahead and copied the files in dnsprov.zip.  The problem is that these are Windows 2000 files and may not have a good effect on a Windows 2003 Server.

The ecstasy came when studying the readme file.  This file showed me that the files I needed were, dnsschema.mof and dnsprov.dll.  When I looked in the…\wbem folder I saw that the Windows Server 2003 version of the files were already there, thus all that I needed to do was to register them.

How To install the dns provider (You have to do this manually)

  • Check that dnsschema.mof and dnsprov.dll are in %windir%\system32\wbem.
  • This is how you register the class information from the Run box:
  • Click on Start, in the Run box type:
    "mofcomp dnsschema.mof"
  • This is how to register the .dll.  At the run box copy and paste:
    "regsvr32 dnsprov.dll"

Check the Properties for Root\MicrosoftDNS

# PowerShell DNS
Clear-Host
$DNSRoot = Get-WmiObject -namespace "root\MicrosoftDNS" -List
$DNSRoot | Where{$_.Name -Notlike "__*"} | Format-Table Name, Property

Note 1: You could substitute root\cimv2 for root\MicrosoftDNS

See more WMI tasks for PowerShell »

PowerShell DNS Summary

To get started configuring DNS via PowerShell make sure that you install the MicrosoftDNS namespace. 

If you like this page then please share it with your friends

 


See More Microsoft PowerShell WMI Examples:

Home   • PowerShell Get-WmiObject   • Win32_ComputerSystem   • Free WMI Monitor

WMI Class  • [WMI] Type  • Win32_printer   • Win32_product   • SystemRestore   • WMI Services

WMI Disk   • DNS   • Memory  • PowerShell -Filter   • Check Server UpTime   • ConvertToDateTime

Please email me if you have a script examples. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.