Share via


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

  • Anonymous
    January 01, 2003
    Micki, DhcpServer PowerShell module is supported on Windows 8/Windows Server 2012. It is not supported on Windows 7.

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

  • Anonymous
    January 01, 2003
    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.

  • Anonymous
    September 17, 2013
    The comment has been removed

  • Anonymous
    September 16, 2014
    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.

  • Anonymous
    January 30, 2015
    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 ?

  • Anonymous
    February 12, 2015
    The comment has been removed

  • Anonymous
    October 02, 2015
    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
    # 10.9.22.0;AMS-SERVER-02;00FF1A60001B;FIleServer
    # So to be clear thats IP;SERVERNAME;MAC;Description
    # Only works from Win 2012 server or higher

    $DHCP = "2008DHCPSERVERNAME"
    $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
    }