Files
PSProxmox/docs/examples/Advanced-MultipleVMsFromTemplate.ps1
T
2025-04-28 14:59:49 -04:00

40 lines
1.5 KiB
PowerShell

# Advanced-MultipleVMsFromTemplate.ps1
# This script demonstrates how to create multiple VMs from a template using the PSProxmox module.
# Import the PSProxmox module
Import-Module PSProxmox
# Connect to the Proxmox VE server
$credential = Get-Credential -Message "Enter your Proxmox VE credentials"
$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Credential $credential -Realm "pam"
# Method 1: Create multiple VMs from a template with default settings
$vms = New-ProxmoxVMFromTemplate -Connection $connection -Node "pve1" -TemplateName "Ubuntu-Template" `
-Prefix "web" -Count 3 -Start
# Display the VM information
$vms
# Method 2: Create multiple VMs from a template with custom settings
$vms = New-ProxmoxVMFromTemplate -Connection $connection -Node "pve1" -TemplateName "Ubuntu-Template" `
-Prefix "db" -Count 2 -StartIndex 1 -Memory 4096 -Cores 2 -DiskSize 50 -Start
# Display the VM information
$vms
# Method 3: Create multiple VMs from a template with IP addresses from a pool
# First, create an IP pool if it doesn't exist
if (-not (Get-ProxmoxIPPool -Name "Production")) {
New-ProxmoxIPPool -Name "Production" -CIDR "192.168.1.0/24" -ExcludeIPs "192.168.1.1", "192.168.1.254"
}
# Create the VMs with IP addresses from the pool
$vms = New-ProxmoxVMFromTemplate -Connection $connection -Node "pve1" -TemplateName "Ubuntu-Template" `
-Prefix "app" -Count 5 -IPPool "Production" -Start
# Display the VM information
$vms
# Disconnect from the server when done
Disconnect-ProxmoxServer -Connection $connection