Powershell命令(DHCP/NPS)
程序员文章站
2023-12-30 14:49:16
...
关于NPS(网络认证服务器)
1.NPS批量添加客户端
Import-Module nps
$content=import-Csv ("E:\AddNpsClient.csv")
$content
foreach ($radius in $content)
{
New-NpsRadiusClient -Name $radius.name -Address $radius.address -SharedSecret !Panpssw2016# |out-Null
}
cmd.exe /c sc.exe control ias 128
2.输出NPS客户端信息
Clear-Content E:\report\xxx.txt
echo "NPS Client" > E:\report\xxxx.txt
Import-Module nps
$A=NpsRadiusClient |Out-String
$regex = [regex]"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b"
$regex.Matches($A)| Select-Object -Property Value >> E:\report\10.37.111.109.txt
3.此脚本解决Powershel命令l需要管理员权限运行,不能直接双击运行的问题。
$path=Split-Path -Parent $MyInvocation.MyCommand.Definition
Start-Process powershell $path\Runshell.ps1 -Verb runas
4.使用VB解决Powershell版本过低导致.ps1脚本不能直接运行的问题。
Set ws = CreateObject("Wscript.Shell")
ws.run "cmd /c TYPE D:\Users\LISHUZE687\Desktop\shell.txt | PowerShell.exe -noprofile -",vnhide
二.关于DHCP服务器:
1.导入DHCP配置数据(Windows2012迁移工具的使用)
Import-SmigServerSetting -FeatureID dhcp -Force -Path C:\DHCPData -Verbose
2.导出租约信息
Get-DhcpServerv4Scope | foreach {Get-DhcpServerv4Lease -ScopeId $_.scopeid | Where-Object {$_.addressstate -eq "Active"}} | Export-Csv c:\clientlease1.csv -NoTypeInformation -Encoding UTF8
3.删除租约信息
Get-DhcpServerv4Scope | Get-DhcpServerv4Lease -AllLeases | Remove-DhcpServerv4Lease
Get-DhcpServerv4Lease -ComputerName xxxx -ScopeId xxxx –AllLeases | Remove-DhcpServerv4Lease -ComputerName xxxx
4.导入租约信息
Import-Csv C:\clientlease4.csv | foreach {Add-DhcpServerv4Lease -IPAddress $_.IPAddress -ScopeId $_.ScopeId -AddressState $_.AddressState -ClientId $_.ClientId -ClientType $_.ClientType -Description $_.Description -DnsRegistration $_.DnsRegistration -DnsRR $_.DnsRR -HostName $_.HostName -LeaseExpiryTime $_.LeaseExpiryTime -NapCapable $True -NapStatus "FullAccess" -PolicyName $_.PolicyName}
5.导出作用域
Import-Csv C:\Scopes.csv | foreach {Get-DhcpServerv4Scope $_.scopeid} | Export-Csv c:\NewScopes.csv -NoTypeInformation -Encoding UTF8
6.导入作用域
Import-Csv C:\NewScopes.csv | foreach {Add-DhcpServerv4Scope -Name $_.Name -StartRange $_.StartRange -EndRange $_.EndRange -SubnetMask $_.SubnetMask -ActivatePolicies $true -Description $_.Description -State Active -Type Dhcp -LeaseDuration $_.LeaseDuration -Delay $_.Delay -MaxBootpClients $_.MaxBootpClients}
7.导出排除地址
C:\NewScopes.csv | foreach {Get-DhcpServerv4ExclusionRange -ScopeId $_.scopeid} | Export-Csv c:\ExcRange-88.1.csv -NoTypeInformation -Encoding UTF8
8.导入排除地址
Import-Csv -Path .\ExcIP.csv | foreach { Add-DhcpServerv4ExclusionRange -ScopeId $_.ScopeId -StartRange $_.StartRange -EndRange $_.EndRange }
9.导出保留地址
Import-Csv C:\NewScopes.csv | foreach {Get-DhcpServerv4Reservation -ScopeId $_.scopeid} | Export-Csv c:\Res-88.1.csv -NoTypeInformation -Encoding UTF8
10.导入保留地址
Import-Csv .\ResIP.csv | foreach {Add-DhcpServerv4Reservation -ScopeId $_.ScopeId -IPAddress $_.IPAddress -ClientId $_.ClientId -Description $_.Description -Name $_.Name -Type $_.Type}
11.导出作用域选项
Import-Csv C:\NewScopes.csv | foreach {Get-DhcpServerv4OptionValue -ScopeId $_.ScopeId}
推荐阅读
-
powershell 执行多条命令
-
Powershell命令(DHCP/NPS)
-
CMD命令行修改.ps1文件(powershell脚本)的默认打开方式
-
win10预览版14971中用将PowerShell替换命令提示符
-
Win10 19H1新增cmd/PowerShell字符缩放:写命令更方便
-
win10预览版14971中用将PowerShell替换命令提示符
-
PowerShell或命令行运行javac xx.java提示“编码GBK的不可映射字符”
-
PowerShell使用Clear-Content命令删除、清空文件内容的例子
-
PowerShell中使用Get-ChildItem命令读取目录、文件列表使用例子和小技巧
-
PowerShell使用Remove-Item命令删除文件、注册表项介绍