Reputation: 107
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.
Upvotes: 1
Views: 10818
Reputation: 16086
Use example resources
Use Video tutorials
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'.
#>
Upvotes: 4