C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
C:\第三步-设置计划任务每5秒自动重启虚拟机.ps1



#----------------------批量添加拨号网卡------------
#虚拟机IP初始信息
$IP="192.168.11."
#虚拟机IP开始值
$IP_START=2
#准备创建虚拟机的数量
$IP_ZENJIA=12
#拨号网卡名称
$NetworkName2="adsl"
#----------------------------下面部分不用修改------------------------
$IP_END=$IP_START+$IP_ZENJIA - 1
for($i=$IP_START;$i -le$IP_END;$i++) {
$VMDIR = $VHDPath + $IP +$I
#虚拟机名称
$VMName = $IP + $i + ".vhdx"
#虚拟机文件所在的完整路径
$VMCFDIR = $VMDIR + "\" + $VMName
#读取该虚拟机指定的拨号信息
$Contents=Import-Csv "c:\aqypppoe.csv"
$csvpppoe=$Contents.csvpppoe[$I]
$csvpassword=$Contents.csvpassword[$I]
$csvvmhost=$Contents.csvvmhost[$I]
$csvvlan=$Contents.csvvlan[$I]
$pshell1=$Contents.pshell[1]
$pshell2=$Contents.pshell[2]
$HYName = $csvvmhost + "/" + $IP + $i + "/" + $csvpppoe
#每5秒重启一个虚拟机
ReStart-VM -Name $HYName -asjob
Sleep 5
}
网友评论