HYPER-V平台 批处理批量创建并配置ADSL帐号到CENTOS模板机中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | @echo off setlocal enabledelayedexpansion rem 首先创建名字为:pppoeswitch的交换机 set prestr=zjwz_3_ rem goto config del /f newvm.txt del /f /s /q d:\hyper-v\vhd\* del /f /s /q e:\hyper-v\vhd\* mkdir d:\hyper-v\vhd mkdir e:\hyper-v\vhd rem powershell "Get-VM | Remove-VM -Force" for /l %%i in (1 1 125) do ( echo copy %%i copy zh0423.vhdx d:\hyper-v\vhd\%%i.vhdx powershell "New-VM -Name " %prestr%%%i " -SwitchName pppoeswitch -MemoryStartupBytes 512MB -VHDPath d:\hyper-v\vhd\%%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-v\vhd\%%i.vhdx powershell "New-VM -Name " %prestr%%%i " -SwitchName pppoeswitch -MemoryStartupBytes 512MB -VHDPath e:\hyper-v\vhd\%%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”
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)