Get the App
SLTechnology News&Howtos  ›  Servers  › 

Hyper-V batch create virtual machines automatically change IP and configure PPPOE dialing

Shulou Source: shulou.com Published: 2022-06-03 04:58:42 11月16日 Update

PowerShell creates virtual machines in bulk:

#-batch create virtual machine script 20190314-

# Virtual machine storage path

$VHDPath= "d:\ vhd\"

# initial information of virtual machine IP

$IP= "192.168.185."

# Virtual Machine IP start value

$IP_START=2

# number of virtual machines to be created

``quantity

$IP_ZENJIA=25

# name of virtual machine Nic

$NetworkName1= "hgpppoe"

$NetworkName2= "nat"

# Dial-up DNS+ password

$DNS1= "202.103.44.150"

$DNS2= "223.5.5.5"

$PPPOEWD= "123789"

# number of virtual machine cpu cores

$LogicPrecesserCount=2

# Virtual machine memory

$MomeryCount=2GB

# template location

$MasterDiskPath= "C:\ mupan.vhdx"

#-the following part does not need to be modified-

$IP_END=$IP_START+$IP_ZENJIA-1

For ($iSuppli / IP / startup / I-le$IP_END;$i++) {

$VMDIR = $VHDPath + $IP + $I

# create a folder where virtual machine disks are stored

Mkdir $VMDIR

# Virtual Machine name

$VMName = $IP + $I + ".vhdx"

# the full path where the virtual machine file is located

$VMCFDIR = $VMDIR + "\" + $VMName

# copy the master disk to the directory where the virtual machine is stored

Copy-Item $MasterDiskPath $VMCFDIR

# read the dialing information specified by the virtual machine

$PPPOE= (Get-Content C:\ adsl.txt-TotalCount $I) [- 1]

# create a virtual machine

$HYName = $IP + $I + "/" + $PPPOE

New-VM-Name $HYName-path $VMDIR-MemoryStartupBytes $MomeryCount-VHDPath $VMCFDIR-SwitchName $NetworkName1

# to the virtual machine disk directory

Cd $VMDIR

# create new private network Nic information

New-Item "ip.txt"-type File

# write intranet Nic information to a file

"IPADDR=$IP$I" | Out-File ip.txt-encoding utf8

# create an automatic dialing script

New-Item "autoad.sh"-type File

# Editing automatic dialing script

"pppoe-setup

Tags: Network card file information script directory path configuration name copy template disk memory quantity server permission system rate master disk production service Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Microsoft OPPO Reno Docker Shulou Tech Info