PowerShell manages DHCP scopes

Source: Internet
Author: User

PowerShell manages DHCP scopes

When it comes to PowerShell believing that administrators are familiar with, of course, PowerShell under Windows Hen Multi-service is different, but for the syntax is the same, why there are multiple PowerShell scripts in Microsoft's products, for Windows The service is using the system's own PowerShell, and for Microsoft Exchange Services is a separate PowerShell program, most notably Microsoft's public cloud needs to download the Azure PowerShell program separately. For different services need to use different PowerShell program to perform different operations to use inconvenient, I hope that Microsoft will be able to fuse, and then import different modules for different service management, the specific relevant introduction is not much introduced, so directly into the subject, Recently some of the company's network has made some special restrictions, for a scope of the address needs to be retained before it can be out of the net, so this brings out the related problems, for the company address allocation is used in the Windows system deployed under the DHCP service for address distribution management, think of a lot of methods, In the end, we want to manage the scope address through PowerShell, mainly today, using PowerShell to manage DHCP server configuration, querying scope information using PowerShell, and finally using PowerShell to bulk add retention address information. specifically see below:

We can refer to Microsoft PowerShell for managing DHCP related documentation.

Https://technet.microsoft.com/library/jj590751.aspx

1. Add address information for multiple scopes to the DHCP reserved zone. The parameter command used is: Netshell

DHCP server server address, if you are performing a local point 127.0.0.1

Scope is DHCP scope information, and operations can be managed if there are multiple scopes within the environment

ReservedIP to add reserved IP address information

The MAC address that corresponds to the need to add reserved IP address information after ReservedIP

Reservedname for reserved names

Descriptname is the descriptive information for the reserved name

Both is the DHCP type that holds address information

Netsh DHCP server 127.0.0.1 scope 10.10.10.0 add reservedip 10.10.10.13 02523idfafag "Reservername" "Descript" "BOTH"

650) this.width=650; "title=" clip_image002 "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ image002 "src=" http://s3.51cto.com/wyfs02/M00/7E/72/wKiom1b_1Hrillt-AAEDJ9_oacQ346.jpg "height=" 484 "/>

Of course, we can also execute the script by defining the variables, by defining the variables and substituting the information in the statement;

$serverip = ' 127.0.0.1 ' $n = ' 10.10.10.0 ' $ip = ' 10.10.10.13 ' $m = ' agaggdi12424 ' $resername = ' haha ' $desc = ' descriptname ' Netsh DHCP server $serverip scope $n add reservedip $ip $m "$resername" "$desc" "BOTH"

650) this.width=650; "title=" clip_image004 "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt = "clip_image004" src= "http://s3.51cto.com/wyfs02/M02/7E/6F/wKioL1b_1SKzG2UBAADgDlAgHYU569.jpg" height= "484"/>

If it is more convenient to read the data format from the local TXT and then transfer to the variables in PowerShell to execute, it is more convenient, the next period is mainly introduced;

127.0.0.1,10.10.10.0,10.10.10.100,03231d66et59,zhangsan,it,both

First, use PowerShell to read the contents of the local TXT file

Get-connect C:\1.txt

650) this.width=650; "title=" clip_image006 "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt = "clip_image006" src= "http://s3.51cto.com/wyfs02/M00/7E/6F/wKioL1b_1SPQS179AACTj5jQlFo666.jpg" height= "456"/>

In fact, the above introduction has been very clear, the use of the command for the Netsh commands for DHCP

Https://technet.microsoft.com/zh-cn/library/bb490941.aspx

650) this.width=650; "title=" clip_image008 "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt = "clip_image008" src= "http://s3.51cto.com/wyfs02/M01/7E/72/wKiom1b_1H7w6-h7AADG13q8duo004.jpg" height= "/>"

As described in bulk additions, the following describes how to display the scope configuration information for DHCP server

Netsh DHCP Server v4 Show All

650) this.width=650; "title=" clip_image010 "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt = "clip_image010" src= "http://s3.51cto.com/wyfs02/M01/7E/6F/wKioL1b_1SaSqx5AAAC3kfJM2rw794.jpg" height= "484"/>

To view binding information for a DHCP server

Netsh DHCP server Show bindings

650) this.width=650; "title=" clip_image012 "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ image012 "src=" http://s3.51cto.com/wyfs02/M02/7E/72/wKiom1b_1IGjLNfCAAC2a32nxfU272.jpg "height=" 529 "/>

We can refer to the Help documentation

Http://www.feiesoft.com/windows/cmd/netsh_dhcp.htm

650) this.width=650; "title=" clip_image014 "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt = "clip_image014" src= "http://s3.51cto.com/wyfs02/M02/7E/72/wKiom1b_1ILBc1DMAAFFaXTQceI724.jpg" height= "365"/>

Querying address information for a specified scope

netsh dhcp server 192.168.0.1 scope 192.168.0.0 dump

650) this.width=650; "title=" clip_image016 "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ image016 "src=" http://s3.51cto.com/wyfs02/M00/7E/72/wKiom1b_1ISTbK3UAAE7vCC6DKM170.jpg "height=" 508 "/>

Query the corresponding MAC address with the specified IP address

(netsh dhcp server scope 10.10.10.0 show Clients | where {$_-match "10.10.10.13"})-split "_"-replace "", ""

650) this.width=650; "title=" clip_image018 "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt = "clip_image018" src= "http://s3.51cto.com/wyfs02/M01/7E/72/wKiom1b_1IWQvAR9AACw4CNKk1Q343.jpg" height= "484"/>

We need to add more than one statement to execute if we batch query.

650) this.width=650; "title=" clip_image020 "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt = "clip_image020" src= "http://s3.51cto.com/wyfs02/M00/7E/6F/wKioL1b_1S2CIa84AAD6BibPOGk410.jpg" height= "484"/>

Define a variable query specifies the IP address information and MAC address of the scope network segment

$ip = ' 10.10.10.0 ' (netsh dhcp server scope $ip show clients)-split "_"-replace "", ""

650) this.width=650; "title=" clip_image022 "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt = "clip_image022" src= "http://s3.51cto.com/wyfs02/M01/7E/6F/wKioL1b_1S7g8kSHAADgnshs9GY155.jpg" height= "396"/>

Defining variables

$ip = ' 10.10.10.0 ' $b = ' 10.10.10.13 ' (netsh dhcp server scope $ip show Clients | where {$_-match "$b"})-split "_"-replace "" ,""

650) this.width=650; "title=" clip_image024 "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt = "clip_image024" src= "http://s3.51cto.com/wyfs02/M02/7E/72/wKiom1b_1ImhDFQwAACrqkYF4iU184.jpg" height= "462"/>

If you need to save the execution result in the specified directory, we need to redirect after executing the script

650) this.width=650; "title=" clip_image026 "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ image026 "src=" http://s3.51cto.com/wyfs02/M02/7E/72/wKiom1b_1ImzfRRtAAA1q5NqplE201.jpg "height=" 191 "/>

650) this.width=650; "title=" clip_image028 "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clip_ image028 "src=" http://s3.51cto.com/wyfs02/M00/7E/72/wKiom1b_1I2wmvYcAABn-iaRy3o579.jpg "height=" 271 "/>

This article from "Gao Wenrong" blog, declined reprint!

PowerShell manages DHCP scopes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.