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

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

Add-DhcpServerv4Scope -ComputerName -Name "Lab-1 Network" -StartRange -EndRange -SubnetMask

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

Get-DhcpServerv6Reservation -ComputerName -Prefix 2001:4898:7020:1020:: 



Comments (8)
  1. teamdhcp says:


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

  2. teamdhcp says:

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

  3. teamdhcp says:

    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.

  4. Micki says:

    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 -ScopeId

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

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

      4Lease], CimException

       + FullyQualifiedErrorId : HRESULT 0x8004100e,Get-DhcpServerv4Lease

  5. Brett M says:

    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.

  6. sajjad says:

    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 ?

  7. Gerold says:

    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:Usersadmin> 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

  8. T G says:

    Hi use this ( thanks to Barry M )

    # Script makes multiple dhcp reservations on an 2008 dhcp server using Win2012 dhcp cmdlet

    # Save this script as an .ps1 file and add Clients.csv in the same folder.
    # example .csv entry
    # Scopeid;Name;Clientid;Description
    # So to be clear thats IP;SERVERNAME;MAC;Description
    # Only works from Win 2012 server or higher

    $Scriptpath = Split-Path $MyInvocation.MyCommand.Path
    $Timestamp = Get-Date -Format yyyyMMdd_HHmmss
    $Logfile = "$($Scriptpath)$($Timestamp)_Add-ClientToDHCP.log"
    $Clients = Import-Csv $ScriptpathClients.csv -Delimiter ";"

    ForEach ($Client in $Clients){
    $ScopeID = $Client.Scopeid
    $ClientID = $Client.Clientid
    $Description = $Client.Description
    $Name = $Client.Name
    $Time = Get-Date -Format HH:mm:ss
    $FreeIP = Get-DhcpServerv4FreeIPAddress -ComputerName $DHCP -ScopeId $ScopeID
    Add-DhcpServerv4Reservation -ComputerName $DHCP -ScopeId $ScopeID -ClientId $ClientID -IPAddress $FreeIP -Description $Description -Name $Name
    "$($Time) | Added reservation $($FreeIP) to scope $($ScopeID) for $($Name)." | Out-File $Logfile

Comments are closed.

Skip to main content