From 9f56234f994c1c2694e972ed6c8b8c4865e63052 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Tue, 5 Dec 2023 09:05:50 +0100 Subject: [PATCH] Add some VM scripts --- scripts/import-vm.ps1 | 4 ++++ scripts/move-vm.ps1 | 3 +++ scripts/new-linux-vm.ps1 | 19 +++++++++++++++++++ scripts/new-windows-vm.ps1 | 18 ++++++++++++++++++ scripts/remove-vm.ps1 | 6 ++++++ 5 files changed, 50 insertions(+) create mode 100644 scripts/import-vm.ps1 create mode 100644 scripts/move-vm.ps1 create mode 100644 scripts/new-linux-vm.ps1 create mode 100644 scripts/new-windows-vm.ps1 create mode 100644 scripts/remove-vm.ps1 diff --git a/scripts/import-vm.ps1 b/scripts/import-vm.ps1 new file mode 100644 index 00000000..634b3a2e --- /dev/null +++ b/scripts/import-vm.ps1 @@ -0,0 +1,4 @@ +$VMName = "debian" +Get-ChildItem "C:\packer\$VMName\Virtual Machines\*.vmcx" | Import-VM -Copy -VhdDestinationPath "C:\VirtualMachines\$VMName\Virtual Hard Disks" -VirtualMachinePath "C:\VirtualMachines\$VMName" -GenerateNewId +Start-VM $VMName +exit 0 # success \ No newline at end of file diff --git a/scripts/move-vm.ps1 b/scripts/move-vm.ps1 new file mode 100644 index 00000000..b6a96180 --- /dev/null +++ b/scripts/move-vm.ps1 @@ -0,0 +1,3 @@ +$VMName = "windows" +Move-VM $VMName HOST2 -IncludeStorage -DestinationStoragePath "D:\VirtualMachines\$VMName" +exit 0 # success \ No newline at end of file diff --git a/scripts/new-linux-vm.ps1 b/scripts/new-linux-vm.ps1 new file mode 100644 index 00000000..0d43b7f3 --- /dev/null +++ b/scripts/new-linux-vm.ps1 @@ -0,0 +1,19 @@ +$VMName = "linux" + + $VM = @{ + Name = $VMName + MemoryStartupBytes = 1GB + Generation = 2 + NewVHDPath = "C:\VirtualMachines\$VMName\Virtual Hard Disks\$VMName.vhdx" + NewVHDSizeBytes = 30GB + BootDevice = "VHD" + Path = "C:\VirtualMachines\" + SwitchName = 'vSwitch' + } + + New-VM @VM + Set-VMProcessor $VMName -count 1 + Add-VMDvdDrive $VMName + Set-VMDvdDrive $VMName -Path "C:\iso\CentOS-8.3.2011-x86_64-minimal.iso" + Set-VMFirmware -EnableSecureBoot Off $VMName +exit 0 # success \ No newline at end of file diff --git a/scripts/new-windows-vm.ps1 b/scripts/new-windows-vm.ps1 new file mode 100644 index 00000000..8ef7212c --- /dev/null +++ b/scripts/new-windows-vm.ps1 @@ -0,0 +1,18 @@ +$VMName = "windows" + + $VM = @{ + Name = $VMName + MemoryStartupBytes = 4GB + Generation = 2 + NewVHDPath = "C:\VirtualMachines\$VMName\Virtual Hard Disks\$VMName.vhdx" + NewVHDSizeBytes = 50GB + BootDevice = "VHD" + Path = "C:\VirtualMachines\" + SwitchName = 'vSwitch' + } + + New-VM @VM + Set-VMProcessor $VMName -count 1 + Add-VMDvdDrive $VMName + Set-VMDvdDrive $VMName -Path "C:\iso\Win10_21H1_English_x64.iso" +exit 0 # success \ No newline at end of file diff --git a/scripts/remove-vm.ps1 b/scripts/remove-vm.ps1 new file mode 100644 index 00000000..3b53dc21 --- /dev/null +++ b/scripts/remove-vm.ps1 @@ -0,0 +1,6 @@ +$VMName = "debian" +$WarningPreference = 'SilentlyContinue' # If VM already stopped +Stop-VM $VMName -Force +Remove-VM $VMName -Force +Remove-Item -Path "C:\VirtualMachines\$VMName" -Recurse +exit 0 # success \ No newline at end of file