mkvm.ps1 avec des function propre s-adm et s-infra OK

This commit is contained in:
Anthony Arnoux 2023-01-31 10:56:10 +01:00
parent a7a9752aa0
commit abad0fcdbc

View File

@ -5,124 +5,151 @@ $ovarelease="2023a"
$ovafogrelease="2023a"
$ovafile="$HOME\Downloads\debian-bullseye-gsb-${ovarelease}.ova"
$ovafilefog="$HOME\Downloads\debian-buster-gsb-${ovafogrelease}.ova"
$vboxmanage="C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"
$deletemode=0
#FONCTIONS
function create_vm{ param([string]$nomvm)
#Importation depuis l'ova
& "$vboxmanage" import "$ovafile" --vsys 0 --vmname "$nomvm"
Write-Host "Machine $nomvm importée"
}
function create_if{ param([string]$nomvm, [string]$nic, [int]$rang, [string]$reseau)
#Création d'une interface
if ($nomvm -and $nic -and $rang -and $reseau) {
#if ("1" -eq "1") {
if ($nic -eq "bridge") {
#Création d'une interface en pont
& "$vboxmanage" modifyvm "$nomvm" --nic"$rang" bridged
& "$vboxmanage" modifyvm "$nomvm" --nictype"$rang" 82540EM
& "$vboxmanage" modifyvm "$nomvm" --cableconnected"$rang" on
& "$vboxmanage" modifyvm "$nomvm" --nicpromisc"$rang" allow-all
Write-Host "$nomvm : IF$rang $nic"
}
elseif ($nic -eq "int") {
#Création d'une interface en reseau interne
& "$vboxmanage" modifyvm "$nomvm" --nic"$rang" intnet
& "$vboxmanage" modifyvm "$nomvm" --intnet"$rang" "$reseau"
& "$vboxmanage" modifyvm "$nomvm" --nictype"$rang" 82540EM
& "$vboxmanage" modifyvm "$nomvm" --cableconnected"$rang" on
& "$vboxmanage" modifyvm "$nomvm" --nicpromisc"$rang" allow-all
Write-Host "$nomvm : IF$rang $nic $reseau"
}
}
}
if ($args[0] -eq "s-adm") {
#Importation depuis l'ova
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" import "$ovafile" --vsys 0 --vmname "s-adm"
#création de la première interface
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "s-adm" --nic1 bridged
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "s-adm" --nictype1 82540EM
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "s-adm" --cableconnected1 on
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "s-adm" --nicpromisc1 allow-all
#création de la deuxième interface
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "s-adm" --nic2 intnet
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "s-adm" --intnet2 "n-adm"
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "s-adm" --nictype2 82540EM
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "s-adm" --cableconnected2 on
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "s-adm" --nicpromisc2 allow-all
create_vm $args[0]
create_if $args[0] "bridge" 1 "null"
create_if $args[0] "int" 2 "n-adm"
}
elseif ($args[0] -eq "s-infra") {
#Importation depuis l'ova
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" import "$ovafile" --vsys 0 --vmname "s-infra"
create_vm $args[0]
create_if $args[0] "int" 1 "n-adm"
create_if $args[0] "int" 2 "n-infra"
#création de la première interface
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "s-infra" --nic1 intnet
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "s-infra" --intnet1 "n-adm"
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "s-infra" --nictype1 82540EM
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "s-infra" --cableconnected1 on
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "s-infra" --nicpromisc1 allow-all
& "$vboxmanage" modifyvm "s-infra" --nic1 intnet
& "$vboxmanage" modifyvm "s-infra" --intnet1 "n-adm"
& "$vboxmanage" modifyvm "s-infra" --nictype1 82540EM
& "$vboxmanage" modifyvm "s-infra" --cableconnected1 on
& "$vboxmanage" modifyvm "s-infra" --nicpromisc1 allow-all
#création de la deuxième interface
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "s-infra" --nic2 intnet
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "s-infra" --intnet2 "n-infra"
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "s-infra" --nictype2 82540EM
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "s-infra" --cableconnected2 on
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "s-infra" --nicpromisc2 allow-all
& "$vboxmanage" modifyvm "s-infra" --nic2 intnet
& "$vboxmanage" modifyvm "s-infra" --intnet2 "n-infra"
& "$vboxmanage" modifyvm "s-infra" --nictype2 82540EM
& "$vboxmanage" modifyvm "s-infra" --cableconnected2 on
& "$vboxmanage" modifyvm "s-infra" --nicpromisc2 allow-all
}
elseif ($args[0] -eq "r-int") {
#Importation depuis l'ova
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" import "$ovafile" --vsys 0 --vmname "r-int"
create_vm($args[0])
#interface 1
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --nic1 intnet
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --intnet1 "n-adm"
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --nictype1 82540EM
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --cableconnected1 on
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --nicpromisc1 allow-all
& "$vboxmanage" modifyvm "r-int" --nic1 intnet
& "$vboxmanage" modifyvm "r-int" --intnet1 "n-adm"
& "$vboxmanage" modifyvm "r-int" --nictype1 82540EM
& "$vboxmanage" modifyvm "r-int" --cableconnected1 on
& "$vboxmanage" modifyvm "r-int" --nicpromisc1 allow-all
#interface 2
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --nic2 intnet
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --intnet2 "n-link"
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --nictype2 82540EM
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --cableconnected2 on
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --nicpromisc2 allow-all
& "$vboxmanage" modifyvm "r-int" --nic2 intnet
& "$vboxmanage" modifyvm "r-int" --intnet2 "n-link"
& "$vboxmanage" modifyvm "r-int" --nictype2 82540EM
& "$vboxmanage" modifyvm "r-int" --cableconnected2 on
& "$vboxmanage" modifyvm "r-int" --nicpromisc2 allow-all
#interface 3
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --nic3 intnet
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --intnet3 "n-wifi"
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --nictype3 82540EM
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --cableconnected3 on
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --nicpromisc3 allow-all
& "$vboxmanage" modifyvm "r-int" --nic3 intnet
& "$vboxmanage" modifyvm "r-int" --intnet3 "n-wifi"
& "$vboxmanage" modifyvm "r-int" --nictype3 82540EM
& "$vboxmanage" modifyvm "r-int" --cableconnected3 on
& "$vboxmanage" modifyvm "r-int" --nicpromisc3 allow-all
#interface 4
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --nic4 intnet
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --intnet4 "n-user"
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --nictype4 82540EM
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --cableconnected4 on
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --nicpromisc4 allow-all
& "$vboxmanage" modifyvm "r-int" --nic4 intnet
& "$vboxmanage" modifyvm "r-int" --intnet4 "n-user"
& "$vboxmanage" modifyvm "r-int" --nictype4 82540EM
& "$vboxmanage" modifyvm "r-int" --cableconnected4 on
& "$vboxmanage" modifyvm "r-int" --nicpromisc4 allow-all
#interface 5
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --nic5 intnet
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --intnet5 "n-infra"
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --nictype5 82540EM
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --cableconnected5 on
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-int" --nicpromisc5 allow-all
& "$vboxmanage" modifyvm "r-int" --nic5 intnet
& "$vboxmanage" modifyvm "r-int" --intnet5 "n-infra"
& "$vboxmanage" modifyvm "r-int" --nictype5 82540EM
& "$vboxmanage" modifyvm "r-int" --cableconnected5 on
& "$vboxmanage" modifyvm "r-int" --nicpromisc5 allow-all
}
elseif ($args[0] -eq "r-ext") {
#Importation depuis l'ova
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" import "$ovafile" --vsys 0 --vmname "r-ext"
create_vm($args[0])
#interface 1
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-ext" --nic1 intnet
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-ext" --intnet1 "n-adm"
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-ext" --nictype1 82540EM
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-ext" --cableconnected1 on
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-ext" --nicpromisc1 allow-all
& "$vboxmanage" modifyvm "r-ext" --nic1 intnet
& "$vboxmanage" modifyvm "r-ext" --intnet1 "n-adm"
& "$vboxmanage" modifyvm "r-ext" --nictype1 82540EM
& "$vboxmanage" modifyvm "r-ext" --cableconnected1 on
& "$vboxmanage" modifyvm "r-ext" --nicpromisc1 allow-all
#interface 2
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-ext" --nic2 intnet
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-ext" --intnet2 "n-dmz"
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-ext" --nictype2 82540EM
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-ext" --cableconnected2 on
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-ext" --nicpromisc2 allow-all
& "$vboxmanage" modifyvm "r-ext" --nic2 intnet
& "$vboxmanage" modifyvm "r-ext" --intnet2 "n-dmz"
& "$vboxmanage" modifyvm "r-ext" --nictype2 82540EM
& "$vboxmanage" modifyvm "r-ext" --cableconnected2 on
& "$vboxmanage" modifyvm "r-ext" --nicpromisc2 allow-all
#interface 3
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-ext" --nic3 bridged
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-ext" --nictype3 82540EM
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-ext" --cableconnected3 on
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-ext" --nicpromisc3 allow-all
& "$vboxmanage" modifyvm "r-ext" --nic3 bridged
& "$vboxmanage" modifyvm "r-ext" --nictype3 82540EM
& "$vboxmanage" modifyvm "r-ext" --cableconnected3 on
& "$vboxmanage" modifyvm "r-ext" --nicpromisc3 allow-all
#interface 4
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-ext" --nic4 intnet
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-ext" --intnet4 "n-linkv"
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-ext" --nictype4 82540EM
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-ext" --cableconnected4 on
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-ext" --nicpromisc4 allow-all
& "$vboxmanage" modifyvm "r-ext" --nic4 intnet
& "$vboxmanage" modifyvm "r-ext" --intnet4 "n-linkv"
& "$vboxmanage" modifyvm "r-ext" --nictype4 82540EM
& "$vboxmanage" modifyvm "r-ext" --cableconnected4 on
& "$vboxmanage" modifyvm "r-ext" --nicpromisc4 allow-all
#interface 5
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-ext" --nic5 intnet
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-ext" --intnet5 "n-link"
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-ext" --nictype5 82540EM
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-ext" --cableconnected5 on
& "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "r-ext" --nicpromisc5 allow-all
& "$vboxmanage" modifyvm "r-ext" --nic5 intnet
& "$vboxmanage" modifyvm "r-ext" --intnet5 "n-link"
& "$vboxmanage" modifyvm "r-ext" --nictype5 82540EM
& "$vboxmanage" modifyvm "r-ext" --cableconnected5 on
& "$vboxmanage" modifyvm "r-ext" --nicpromisc5 allow-all
}
elseif ($args[0] -eq "test") {
fonction1 $args[0] $args[1]
}