Hyper-V creates virtual machines in batches to automatically change the IP address and configure pppoe dialing

Source: Internet
Author: User
Powershell:

# Virtual Machine storage path
$ Vhdpath = "D: \ suanya \"
# Virtual Machine naming rules
$ IP = "192.168.155 ."
# Virtual Machine Nic name
$ Networkname1 = "pppoe"
$ Networkname2 = "Nat"
# Number of Virtual Machine CPU Cores
$ Logicprecessercount = 2
# VM memory
$ Momerycount = 2 GB
# Template location
$ Masterdiskpath = "C: \ 192.168.155.51.vhdx"
# Number of virtual machines created. The first digit is the start IP address, and the second digit is the end IP address.
For ($ I = 2; $ I-le26; $ I ++ ){
$ Vmdir = $ vhdpath + $ IP + $ I
# Creating VM folders
Mkdir $ vmdir
# Virtual Machine name
$ Vmname = $ IP + $ I + ". vhdx"
# Complete virtual machine file path
$ Vmcfdir = $ vmdir + "\" + $ vmname
# Copy the master disk to the directory where the VM is stored
Copy-item $ masterdiskpath $ vmcfdir
# Create a virtual machine
$ Hyname = $ IP + $ I
New-VM-name $ hyname-path $ vmdir-memorystartupbytes $ momerycount-vhdpath $ vmcfdir-switchname $ networkname1
# To the Virtual Machine disk directory
CD $ vmdir
# Creating IP Nic Information
New-item "ip.txt"-type file
# Write IP Nic information to the file
"Ipaddr = $ IP $ I" | out-file ip.txt-encoding utf8
# Create an automatic dialing script
New-item "autoad. Sh"-type file
# Editing an automatic dialing script
"Pppoe-setup <EOF" | add-content autoad. Sh-encoding utf8
"" | Add-content autoad. Sh-encoding utf8
$ Pppoe = (get-content c: \ adsl.txt-totalcount 2) [-1]
"$ Pppoe" | add-content autoad. Sh-encoding utf8
"Eth0" | add-content autoad. Sh-encoding utf8
"No" | add-content autoad. Sh-encoding utf8
"202.103.44.150" | add-content autoad. Sh-encoding utf8
"8.8.8.8" | add-content autoad. Sh-encoding utf8
"963852" | add-content autoad. Sh-encoding utf8
"963852" | add-content autoad. Sh-encoding utf8
"Yes" | add-content autoad. Sh-encoding utf8
"0" | add-content autoad. Sh-encoding utf8
"Yes" | add-content autoad. Sh-encoding utf8
"Y" | add-content autoad. Sh-encoding utf8
"EOF" | add-content autoad. Sh-encoding utf8
# Copy the ISO generated script to the Virtual Machine directory
Copy-item C:/ISO. Bat $ vmdir
# Setting ultraiso Environment Variables
$ ENV: Path = $ ENV: path + "; C: \ Program Files (x86) \ ultraiso"
# Execute the ISO generation script
CMD/c iso. bat
# Mounting ISO files to virtual machines
Set-vmdvddrive-vmname $ hyname-path $ vmdir \ IP. ISO
# Add a NIC adapter and mount the NIC
Add-vmnetworkadapter $ hyname-name network2
Connect-vmnetworkadapter $ hyname-name network2 $ networkname2
# Set the number of Virtual Machine kernels
Set-vmprocessor $ hyname-count $ logicprecessercount
# Set the speed of all NICs to 10 MB
# Set-vmnetworkadapter-vmname $ hyname-maximumbandwidth 10000000
# Deleting NICs
# Remove-vmnetworkadapter-vmname $ hyname-vmnetworkadaptername network2
# Enable vro Protection
Set-vmnetworkadapter $ hyname-routerguard on
# Start a virtual terminal
Start-VM-name $ hyname
}

Encapsulate the ISO image package ISO. BAT:

Ultraiso-volume iso-file "% Cd % \ ip.txt"-file "% Cd % \ autoad. Sh"-output "% Cd % \ IP. ISO"

Centos automatically modifies IP addresses and configures pppoe dial-up autoad. sh:

#! /Bin/bash
Mount/dev/CDROM/mnt
CP/mnt/ip.txt
CP/mnt/autoad. sh/autoad. Sh
Sed-I's/^ \ XeF \ xbb \ xbf // G'/ip.txt
Sed-I's/^ \ XeF \ xbb \ xbf // G'/autoad. Sh
Dos2unix/ip.txt
Dos2unix/autoad. Sh
CAT/ip.txt>/etc/sysconfig/network-scripts/ifcfg-eth1
Chmod 777/autoad. Sh
Service Network restart
SH/autoad. Sh
Rm-RF/ip.txt
Rm-RF/autoad. Sh
Eject/dev/CDROM

Create a virtual machine

1. Copy ultraiso.exe=iso.batw.adsl.txt + create a VM and change IP address. PS1 to the c root directory of the server.
2.install ultraiso.exe in the server. Use the default path for the installation directory. Do not modify it!
3. use powershell to open the script file, modify the template file path, store the Virtual Machine path, Nic name/speed, and IP address information (only IP addresses can be written, without additional information), machine configuration/quantity, and other information
4. Run the script to create multiple virtual machines and modify IP addresses automatically.
5. Use passport software and use Excel to import ing information in batches
6. Test remote connection. The VM is created.

Centos master disk Creation
1. Modify the NIC configuration file and delete the line "ipaddr = 192.168.2.2" in the NIC configuration file.
2. Upload gaiip. Sh to the system/directory.
3. Add the gaiip. Sh execution permission
Chmod + x/gaiip. Sh
4. Edit startup items
VI/etc/rc. d/rc. Local
Add a script path
/Gaiip. Sh
Add the execution permission for the startup Item
Chmod + x/etc/rc. d/rc. Local
5. Shut down the virtual machine. The virtual machine disk file can be used to create a system template for Automatic Virtual Machine creation.

Hyper-V creates virtual machines in batches to automatically change the IP address and configure pppoe dialing

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.