1

Is it possible to use Powershell to find a DHCP client in a gigantic list of DHCP servers and scopes?

I work for a hospital that has multiple DHCP servers (one for each region) with multiple scopes (upwards of 50 DHCP scopes for each server. I am trying to find a way that I can write a Powershell script to sift through all servers and scopes and come back with the relevant information needed for my (manual) server decommission process rather than having to do this manually.

We do have applications and tools (Solarwinds) in place that can get me the information that I need, but it's involved and time consuming and I'd rather have this Powershell script a "one-stop shop" script to run to gather my information and clean up the DHCP inventory. And eventually have it baked into the entire end-to-end process for decommissioning the servers. My dream is to be able to run a script, give it the server name and have the process run through and clean out everything from DHCP to DNS to AD Users and Computers. But I'll start small for now.

5
  • 2
    Anything possible is only possible if you know what you want, know where to start, and using the right tool(s). However, SO has rules: Provide MRE --- How to ask --- Don't ask --- Proper Topic. Have you looked at the available cmdlets? What have you searched for? What have you tried? Post your code. The common refrain here is that SO is not a script writing service. Folks can help, but you must show. Commented Oct 10, 2020 at 19:47
  • 1
    I should have known better than to ask a question here. Thanx for showing me out of your cool kids sandbox. Commented Oct 14, 2020 at 15:35
  • ;-} Nope, questions are fine, it's why we are all here. However, they just must fit the rules. ;-} Well, unless it's really interesting, and some folks will dive into it with you or if they are just feeling kind. ;-} Even on the 'kind' part, one can get chastised by others for doing so, if it (the question) does not fit the SO rules. Col kids sandbox. ;--}. Nope, just the internet, and your favorite search engine, or the SO search box at the top of this page. Just searhc 'PowerShell DHCP' Commented Oct 14, 2020 at 15:44
  • 1
    I posted the same question verbatim on Reddit and received a positive response. reddit.com/r/PowerShell/comments/jb4fnd/… Commented Oct 14, 2020 at 21:11
  • Comparing communities is really moot. Each community is different and each has its own rules, moderator, members; and participants will do what they do on each. I've seen the same if not each pushback in many cases on Reddit as well. So, take help from where you get it. Yet, folks on all sies in this vein are doing this for free on their own time. Hence why the effort from posters is appreciated. for more expedient and more prudent responses can be delivered. Commented Oct 14, 2020 at 21:53

1 Answer 1

4

Use example resources

'PowerShell DHCP'

Use Video tutorials

'Youtube DHCP management'

Use the built-in cmdlets

Get-Command -Name '*DHCP*' | 
Where-Object -Property Name -like '*scope*' | 
Format-Table -AutoSize
# Results
<#
CommandType Name                                     Version Source    
----------- ----                                     ------- ------    
Function    Add-DhcpServerv4FailoverScope            2.0.0.0 DhcpServer
Function    Add-DhcpServerv4MulticastScope           2.0.0.0 DhcpServer
Function    Add-DhcpServerv4Scope                    2.0.0.0 DhcpServer
Function    Add-DhcpServerv4Superscope               2.0.0.0 DhcpServer
Function    Add-DhcpServerv6Scope                    2.0.0.0 DhcpServer
Function    Get-DhcpServerv4MulticastScope           2.0.0.0 DhcpServer
Function    Get-DhcpServerv4MulticastScopeStatistics 2.0.0.0 DhcpServer
Function    Get-DhcpServerv4Scope                    2.0.0.0 DhcpServer
Function    Get-DhcpServerv4ScopeStatistics          2.0.0.0 DhcpServer
Function    Get-DhcpServerv4Superscope               2.0.0.0 DhcpServer
Function    Get-DhcpServerv4SuperScopeStatistics     2.0.0.0 DhcpServer
Function    Get-DhcpServerv6Scope                    2.0.0.0 DhcpServer
Function    Get-DhcpServerv6ScopeStatistics          2.0.0.0 DhcpServer
Function    Remove-DhcpServerv4FailoverScope         2.0.0.0 DhcpServer
Function    Remove-DhcpServerv4MulticastScope        2.0.0.0 DhcpServer
Function    Remove-DhcpServerv4Scope                 2.0.0.0 DhcpServer
Function    Remove-DhcpServerv4Superscope            2.0.0.0 DhcpServer
Function    Remove-DhcpServerv6Scope                 2.0.0.0 DhcpServer
Function    Rename-DhcpServerv4Superscope            2.0.0.0 DhcpServer
Function    Set-DhcpServerv4MulticastScope           2.0.0.0 DhcpServer
Function    Set-DhcpServerv4Scope                    2.0.0.0 DhcpServer
Function    Set-DhcpServerv6Scope                    2.0.0.0 DhcpServer
#>

Use the examples from the help files to get started or complete your task

# Get specifics for a module, cmdlet, or function
(Get-Command -Name Get-DhcpServerv4Scop).Parameters
(Get-Command -Name Get-DhcpServerv4Scop).Parameters.Keys
Get-help -Name Get-DhcpServerv4Scop -Examples
Get-help -Name Get-DhcpServerv4Scop -Full
Get-help -Name Get-DhcpServerv4Scop -Online

# Find all cmdlets / functions with a target parameter
Get-Command -CommandType Cmdlet |
Where-Object {
    Try {$PSItem.parameters.keys -match 'credential'}
    Catch{} 
}|
Out-GridView -PassThru -Title '
Available cmdlets which has a specific parameter'

Get-Command -CommandType Function |
Where-Object {
    Try {$PSItem.parameters.keys -match 'credential'}
    Catch{} 
}|
Out-GridView -PassThru -Title '
Available functions which has a specific parameter'

# Get property enums/options for a specifc cmdlet/function
(Get-Service | Select-Object -First 1).Status.GetType()
[System.ServiceProcess.ServiceControllerStatus]::
GetNames([System.ServiceProcess.ServiceControllerStatus])

Look for other modules/scripts to leverage

Find-Module -Name '*DHCP*' | Format-Table -AutoSize
# Results
<#
Version Name                     Repository Description                                                                                                                  
------- ----                     ---------- -----------                                                                                                                  
2.0.0.0 xDhcpServer              PSGallery  Module with DSC Resources for DHCP Server area                                                                               
1.3     DHCPClient               PSGallery  Sample module for retrieving DHCP client details, based on the script published by Ingmar Verheij at https://www.ingmarver...
1.2.1   DHCPMigration            PSGallery  A module to copy various DHCP information from 1 server to another.                                                          
1.0.0.3 Read-DHCPLogFiles        PSGallery  A small PS module to read DHCP txt logs                                                                                      
1.3     cDhcpServerDynamicUpdate PSGallery  Class based resource to configure DHCP server dynamic updates 
#>

Find-Script -Name '*DHCP*' | Format-Table -AutoSize
# Results
<#
Version Name                               Repository Description                                                                     
------- ----                               ---------- -----------                                                                     
1.0.0   NetIPInterface_EnableDHCP_Config   PSGallery  Enabling DHCP for the IPv4 Address and DNS on the adapter with alias 'Ethernet'.
1.0.0   DnsServerAddress_EnableDHCP_Config PSGallery  Enabling DHCP for the IPv4 Address and DNS on the adapter with alias 'Ethernet'.
#>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.