@echo off setlocal enabledelayedexpansion rem 首先创建名字为:pppoeswitch的交换机 set prestr=zjwz_3_ rem goto config del /f newvm.txt del /f /s /q d:hyper-vvhd* del /f /s /q e:hyper-vvhd* mkdir d:hyper-vvhd mkdir e:hyper-vvhd rem powershell "Get-VM | Remove-VM -Force" for /l %%i in (1 1 125) do ( echo copy %%i copy zh0423.vhdx d:hyper-vvhd\%%i.vhdx powershell "New-VM -Name "%prestr%%%i" -SwitchName pppoeswitch -MemoryStartupBytes 512MB -VHDPath d:hyper-vvhd\%%i.vhdx" powershell "Set-VMProcessor "%prestr%%%i" -Count 2" powershell "Get-VM -VMName %prestr%%%i |Set-VM -AutomaticStopAction ShutDown" rem echo Set-VMMemory %prestr%%%i -DynamicMemoryEnabled $true -MinimumBytes 64MB -StartupBytes 256MB -MaximumBytes 512MB -Priority 80 -Buffer 25 ) for /l %%i in (126 1 250) do ( echo copy %%i copy zh0423.vhdx e:hyper-vvhd\%%i.vhdx powershell "New-VM -Name "%prestr%%%i" -SwitchName pppoeswitch -MemoryStartupBytes 512MB -VHDPath e:hyper-vvhd\%%i.vhdx" powershell "Set-VMProcessor "%prestr%%%i" -Count 2" powershell "Get-VM -VMName %prestr%%%i |Set-VM -AutomaticStopAction ShutDown" rem echo Set-VMMemory %prestr%%%i -DynamicMemoryEnabled $true -MinimumBytes 64MB -StartupBytes 256MB -MaximumBytes 512MB -Priority 80 -Buffer 25 ) rem powershell "Get-VM !prestr!* | Add-VMNetworkAdapter -Name pppoe -switchName pppoeswitch" for /l %%i in (1 1 250) do ( echo starting !prestr!%%i powershell "start-VM -Name !prestr!%%i" ) ping -n 300 127.0.0.1 >nul 2>nul for /l %%i in (1 1 250) do ( echo suspend !prestr!%%i powershell "Suspend-VM –Name !prestr!%%i" ) rem config rem 配置虚拟机信息 set mydir=%cd% set user=aa set pass=aa echo !n! for /l %%i in (1 1 250) do ( set m=0 set n=0 set /a n=%%i+9 set /a n=!n!/10 for /f "delims=, tokens=1,2,3" %%j in (!mydir!wh.txt) do ( set /a m=m+1 if !m! equ !n! ( set user=%%j set pass=%%k set vlanid=%%l echo "!prestr!%%i n=!n! %%j %%k %%l" ) ) rem powershell "Get-VMNetworkAdapter -VMName !prestr!%%i -Name pppoe|Set-VMNetworkAdapterVlan -Access -VlanId !vlanid!" powershell "Get-VMNetworkAdapter -VMName "!prestr!%%i" |Set-VMNetworkAdapterVlan -Untagged" powershell "Resume-VM -Name !prestr!%%i" ( echo sed -i "s/07449411799/a123456/dtvps00058/!user!/!pass!/!prestr!%%i/" /etc/motd echo sed -i "s/192.168.12.129/10.10.3.%%i/" /etc/sysconfig/network-scripts/ifcfg-eth0 echo sed -i "s/07449411799/!user!/" /etc/sysconfig/network-scripts/ifcfg-ppp0 echo echo -e "!user! * !pass!"^>/etc/ppp/chap-secrets echo echo -e "!user! * !pass!"^>/etc/ppp/pap-secrets echo hostnamectl set-hostname "!prestr!%%i" )>"%mydir%cmd.txt" ping -n 10 192.168.12.129 >nul 2>nul echo y|"%mydir%plink.exe" root@192.168.12.129 -P 22 -pw dtvps0421 -m "%mydir%cmd.txt" powershell "stop-vm !prestr!%%i" ping 127.0.0.1 -n 2 127.0.0.1 >nul 2>nul powershell "Get-VMNetworkAdapter -VMName "!prestr!%%i" |Set-VMNetworkAdapterVlan -Access -VlanId !vlanid! )
上面是批处理文件,需要用到plink.exe,到putty官方网站下载
密码文件是wh.txt格式是“帐号,密码,VLAN”