PowerShell adds a reserved address in bulk through variables and arrays

Source: Internet
Author: User
Tags vars

PowerShell adds a reserved address in bulk through variables and arrays

Our last article introduced the simple management of DHCP scopes via PowerShell, and today describes the use of PowerShell-defined variables and arrays for bulk add reserved IP address information under DHCP scopes, as shown below:

We will first use the Get-content file path to read the local files and then use the variables to get the local files. After reading the contents of the local file, the data of each row is executed through a foreach loop, and each line defines multiple data, all of which need to be done using an array, whether the script above starts with [0] and then configures the command to complete the operation.

The first is to define the local text data information

127.0.0.1 Management IP for DHCP server

10.10.10.0 scope information for DHCP server

10.10.10.X for reserved IPs that need to be added under the DHCP server scope

XXXXXXXX. X is the MAC address of the reserved IP that needs to be added under the DHCP server scope

Names display name reserved for DHCP

DESC description information reserved for DHCP

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/M01/7E/73/wKiom1b_6ryAtX9RAAB-radoG-w867.jpg "height=" 307 "/>

The next step is to define the script.

$file =get-content D:\test.txtforeach ($line in $file) {$vars = $line-split "," $serverip = $vars [0] $n = $vars [1] $ip = $vars [2 ] $m = $vars [3] $resername = $vars [4] $desc = $vars [5]netsh DHCP server $serverip scope $n add reservedip $ip $m "$resername" $de SC "" BOTH "}

Start execution and execution success

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;padding-right:0px, "border=" 0 "alt=" clip_ image004 "src=" http://s3.51cto.com/wyfs02/M00/7E/73/wKiom1b_6r3yKXsLAADEm61Dt9g740.jpg "height=" 484 "/>

To view the execution results of a DHCP server

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// S3.51cto.com/wyfs02/m02/7e/73/wkiom1b_6r-rgvjtaagfvmdeqna315.png "height=" 484 "/>

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

PowerShell adds a reserved address in bulk through variables and arrays

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.