Microsoft Windows DHCP Team Blog

The world's most deployed DHCP Server! Deploy and discuss about your fav. server, here!

Using Windows 8 DHCP PowerShell cmdlets with DHCP server running on Windows Server 2008 or Windows Server 2008 R2

Using Windows 8 DHCP PowerShell cmdlets with DHCP server running on Windows Server 2008 or Windows Server 2008 R2

  • Comments 7
  • Likes

Windows Server 2012 and Remote Server Administration Tool (RSAT) for Windows 8 ships with DHCP Server PowerShell cmdlets. You can read more about it in this blog. All these cmdlets can also be used to manage DHCP server running on Windows Server 2008 or Windows Server 2008 R2. There are two ways to run any of the DHCP PowerShell Cmdlets against a remote DHCP server. You can use the DNS name or IP address of the remote computer running the DHCP server in the –ComputerName parameter. Alternatively, you can use –CimSession with input of DNS name/IP address of the remote computer running the DHCP server. With –CimSession, you can also use the a session object, such as the output of a New-CimSession or Get-CimSession cmdlet. When the remote target DHCP server is running on Windows Server 2008 R2 or Windows Server 2008, you will need to use –ComputerName to run the cmdlet.. -CimSession is not supported when the target DHCP server is running on Windows Server 2008 or Windows Server 2008R2. Here is a bit of innards of how DHCP PowerShell works which explains this behaviour. All the DHCP Server PowerShell cmdlets call the DHCP server WMI provider. DHCP Server WMI provider which is installed as part of DHCP RSAT on Windows 8 or Windows Server 2012, in turn uses the DHCP Server Management C API which uses RPC transport. If a DHCP Server PowerShell cmdlet is called with –ComputerName parameter, the PowerShell cmdlet calls the DHCP WMI provider on the local computer which in turn calls the DHCP Server C API on the target computer specified in ComputerName. If the DHCP Server PowerShell cmdlet is called with –CimSession, the PowerShell cmdlet calls the DHCP WMI provider on the computer specified in -CimSession. The WMI provider in this case calls the DHCP Server API on the computer on which WMI provider is running.

Since DHCP Server WMI provider is not supported on Windows Server 2008 and Windows Server 2008 R2, you need to use –ComputerName while using DHCP PowerShell to manage a DHCP server running on Windows Server 2008 or Windows Server 2008 R2.

Below are some examples of the usage of -ComputerName parameter in DHCP PowerShell cmdlets:

This example adds a new IPv4 scope on the remote DHCP server dhcpwin2k8server.contoso.com.

Add-DhcpServerv4Scope -ComputerName dhcpwin2k8server.contoso.com -Name "Lab-1 Network" -StartRange 10.10.10.1 -EndRange 10.10.10.254 -SubnetMask 255.255.255.0

The example below gets the information for all the reserved IPv6 addresses in the specified scope on the remote DHCP server dhcpwin2k8server.contoso.com.

Get-DhcpServerv6Reservation -ComputerName dhcpwin2k8server.contoso.com -Prefix 2001:4898:7020:1020:: 

 

Team DHCP

Comments
  • When im trying to do some work from my Win7 ENT with imported PSv3 Dhcpserver module, i get this error?

    My console fully recognizes the command and the imported CMdlet ( from a Win8 client) but keep getting this error , Anyone tryed this "Stunt" before?

    ---------------------------Error in PS console-------------------------------------------------

    Get-DhcpServerv4Lease : Invalid namespace

    At line:1 char:1

    + Get-DhcpServerv4Lease -ComputerName 10.8.4.5 -ScopeId 10.49.65.192

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

       + CategoryInfo          : MetadataError: (PS_DhcpServerv4Lease:root/Microsoft/...cpServerv4Lease) [Get-DhcpServerv

      4Lease], CimException

       + FullyQualifiedErrorId : HRESULT 0x8004100e,Get-DhcpServerv4Lease

  • Micki,

    DhcpServer PowerShell module is supported on Windows 8/Windows Server 2012. It is not supported on Windows 7.

  • While not supported, as long as you are running powershell 4.0, I was able to copy the module off the dhcp server to my local workstation. Then you just need to use the -CimSession switch to point to your DHCP server. Works great for me.

  • On windows 8.1 , Powershell 4 is giving me following errors - Permission denied - Access denied on DHCP server all DHCP commands are being rejected, as normal domain user of Acitve directory do i need WMI remote access rights on all DHCP servers or I should be added to DHCP Remote admins group so that power shell scripts for DHCP Server from windows 8.1 pro will work ?

  • Sajjad, the domain user who is running these cmdlets needs to be member of the DHCP administrators group on the DHCP server. He/she will also need WMI remote access.

  • I have a similiar issue:
    I have a Server 2008R2, updated with WMF to run the DHCP cmdlets; but I can't get them with get-module so I took a Server 2012 and copied it to the server (which was OK); and I used the import-module cmdlet without any error but when I want to use it, there are the following errors:

    PS C:\Users\admin> Get-DhcpServerv4Scope -CimSession FQDN-of-Server
    Get-DhcpServerv4Scope : The WS-Management service cannot process the request. The CIM namespace
    root/Microsoft/Windows/DHCP is invalid.
    At line:1 char:1
    + Get-DhcpServerv4Scope -CimSession FQDN-of-Server
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (PS_DhcpServerv4Scope:root/Microsoft/...cpServerv4Scope) [Get-DhcpServer
    v4Scope], CimException
    + FullyQualifiedErrorId : HRESULT 0x80338000,Get-DhcpServerv4Scope
    + PSComputerName : FQDN-of-Server

    Any idea, what I did wrong?
    thanks in advance

  • Gerold, what you are trying (copying DHCP PowerShell module to 2008R2) is neither tested nor officially supported.
    Have you imported the DHCP PS module.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment