如何解决使用Powershell获取DHCP客户端信息
是否可以使用Powershell在庞大的DHCP服务器和作用域列表中找到DHCP客户端?
我在一家医院工作,医院有多个DHCP服务器(每个区域一个),每个服务器具有多个作用域(每个服务器最多50个DHCP作用域)。我试图找到一种方法,可以编写Powershell脚本来筛选所有内容服务器和范围,然后返回(手动)服务器停用过程所需的相关信息,而不必手动进行。
我们确实有适当的应用程序和工具(Solarwinds),可以为我获取所需的信息,但是它涉及并且耗时,我宁愿将此Powershell脚本作为“一站式”脚本来运行收集我的信息并清理DHCP清单。最终将其纳入整个端对端过程中,以停用服务器。我的梦想是能够运行一个脚本,为其指定服务器名称,并运行该过程并清除从DHCP到DNS到AD用户和计算机的所有内容。但我现在将从小处着手。
解决方法
使用示例资源
使用视频教程
使用内置的cmdlet
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
#>
使用帮助文件中的示例开始或完成任务
# 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])
寻找其他模块/脚本来利用
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'.
#>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。