关于NPS和DHCP的powershell命令

关于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}

猜你喜欢

转载自blog.csdn.net/u013181216/article/details/80303056