Add comprehensive documentation and examples

This commit is contained in:
Alphaeus Mote
2025-04-28 14:59:49 -04:00
parent 45433064b5
commit c4bea36ece
16 changed files with 2077 additions and 23 deletions
@@ -0,0 +1,39 @@
# 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
+55
View File
@@ -0,0 +1,55 @@
# Advanced-VMBuilder.ps1
# This script demonstrates how to create a VM using the builder pattern with 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"
# Create a VM builder
$builder = New-ProxmoxVMBuilder -Name "web-server"
# Configure the VM using the builder pattern
$builder.WithMemory(4096) # 4 GB of memory
.WithCores(2) # 2 CPU cores
.WithSockets(1) # 1 CPU socket
.WithDisk(50, "local-lvm") # 50 GB disk on local-lvm storage
.WithNetwork("virtio", "vmbr0") # virtio network on vmbr0 bridge
.WithIPConfig("192.168.1.10/24", "192.168.1.1") # Static IP configuration
.WithDescription("Web server for production") # Description
.WithStart($true) # Start the VM after creation
# Create the VM using the builder
$vm = New-ProxmoxVM -Connection $connection -Node "pve1" -Builder $builder
# Display the VM information
$vm
# Create another VM with a more complex configuration
$builder = New-ProxmoxVMBuilder -Name "db-server"
# Configure the VM using the builder pattern
$builder.WithMemory(8192) # 8 GB of memory
.WithCores(4) # 4 CPU cores
.WithSockets(2) # 2 CPU sockets
.WithDisk(100, "local-lvm") # 100 GB primary disk on local-lvm storage
.WithAdditionalDisk(200, "local-lvm") # 200 GB additional disk on local-lvm storage
.WithNetwork("virtio", "vmbr0") # virtio network on vmbr0 bridge
.WithAdditionalNetwork("virtio", "vmbr1") # Additional network interface on vmbr1
.WithIPConfig("192.168.1.20/24", "192.168.1.1") # Static IP configuration for first interface
.WithCPUType("host") # CPU type
.WithVGA("std") # VGA type
.WithBoot("order=scsi0;net0") # Boot order
.WithDescription("Database server for production") # Description
.WithStart($true) # Start the VM after creation
# Create the VM using the builder
$vm = New-ProxmoxVM -Connection $connection -Node "pve1" -Builder $builder
# Display the VM information
$vm
# Disconnect from the server when done
Disconnect-ProxmoxServer -Connection $connection
+27
View File
@@ -0,0 +1,27 @@
# Basic-Connection.ps1
# This script demonstrates how to connect to a Proxmox VE server using the PSProxmox module.
# Import the PSProxmox module
Import-Module PSProxmox
# Method 1: Connect using username and password
$securePassword = ConvertTo-SecureString "password" -AsPlainText -Force
$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Username "root" -Password $securePassword -Realm "pam"
# Method 2: Connect using a credential object
$credential = Get-Credential -Message "Enter your Proxmox VE credentials"
$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Credential $credential -Realm "pam"
# Method 3: Connect using an API token
$secureSecret = ConvertTo-SecureString "secret" -AsPlainText -Force
$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -ApiToken "root@pam!token" -ApiTokenSecret $secureSecret
# Method 4: Connect with SSL certificate validation disabled (not recommended for production)
$securePassword = ConvertTo-SecureString "password" -AsPlainText -Force
$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Username "root" -Password $securePassword -Realm "pam" -SkipCertificateValidation $true
# Display the connection information
$connection
# Disconnect from the server when done
Disconnect-ProxmoxServer -Connection $connection
+34
View File
@@ -0,0 +1,34 @@
# Basic-CreateVM.ps1
# This script demonstrates how to create a new VM 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 a basic VM
$vm = New-ProxmoxVM -Connection $connection -Node "pve1" -Name "test-vm" -Memory 2048 -Cores 2 -DiskSize 32 -Start
# Display the VM information
$vm
# Method 2: Create a VM with more options
$vm = New-ProxmoxVM -Connection $connection -Node "pve1" -Name "web-server" `
-Memory 4096 -Cores 2 -Sockets 1 -DiskSize 50 -Storage "local-lvm" `
-OSType "l26" -NetworkModel "virtio" -NetworkBridge "vmbr0" `
-Description "Web server for testing" -Start
# Display the VM information
$vm
# Method 3: Create a VM with a specific ID
$vm = New-ProxmoxVM -Connection $connection -Node "pve1" -Name "db-server" -VMID 200 `
-Memory 8192 -Cores 4 -DiskSize 100 -Storage "local-lvm" -Start
# Display the VM information
$vm
# Disconnect from the server when done
Disconnect-ProxmoxServer -Connection $connection
+43
View File
@@ -0,0 +1,43 @@
# Cluster-CreateBackup.ps1
# This script demonstrates how to create a cluster backup 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 a cluster backup with default settings
$backup = New-ProxmoxClusterBackup -Connection $connection
# Display the backup information
$backup
# Method 2: Create a cluster backup with compression
$backup = New-ProxmoxClusterBackup -Connection $connection -Compress
# Display the backup information
$backup
# Method 3: Create a cluster backup and wait for it to complete
$backup = New-ProxmoxClusterBackup -Connection $connection -Compress -Wait -Timeout 600
# Display the backup information
$backup
# Method 4: Get all cluster backups
$backups = Get-ProxmoxClusterBackup -Connection $connection
# Display the backups
$backups
# Method 5: Get a specific cluster backup
$backupID = $backup.BackupID
$specificBackup = Get-ProxmoxClusterBackup -Connection $connection -BackupID $backupID
# Display the specific backup
$specificBackup
# Disconnect from the server when done
Disconnect-ProxmoxServer -Connection $connection
+69
View File
@@ -0,0 +1,69 @@
# PSProxmox Examples
This directory contains example scripts for the PSProxmox module.
## Basic Examples
- [Connect to a Proxmox VE server](Basic-Connection.ps1)
- [Get information about VMs](Basic-GetVMs.ps1)
- [Create a new VM](Basic-CreateVM.ps1)
- [Start, stop, and restart VMs](Basic-VMPowerManagement.ps1)
- [Remove a VM](Basic-RemoveVM.ps1)
## Advanced Examples
- [Create a VM using the builder pattern](Advanced-VMBuilder.ps1)
- [Create multiple VMs from a template](Advanced-MultipleVMsFromTemplate.ps1)
- [Create a VM with a static IP address](Advanced-VMWithStaticIP.ps1)
- [Create a VM with multiple disks](Advanced-VMWithMultipleDisks.ps1)
- [Create a VM with multiple network interfaces](Advanced-VMWithMultipleNetworks.ps1)
## Cluster Management Examples
- [Join a node to a cluster](Cluster-JoinNode.ps1)
- [Remove a node from a cluster](Cluster-RemoveNode.ps1)
- [Create a cluster backup](Cluster-CreateBackup.ps1)
- [Restore a cluster backup](Cluster-RestoreBackup.ps1)
## Storage Management Examples
- [Get information about storage](Storage-GetStorage.ps1)
- [Create a new storage](Storage-CreateStorage.ps1)
- [Remove a storage](Storage-RemoveStorage.ps1)
## Network Management Examples
- [Get information about network interfaces](Network-GetInterfaces.ps1)
- [Create a new network interface](Network-CreateInterface.ps1)
- [Remove a network interface](Network-RemoveInterface.ps1)
## User and Role Management Examples
- [Get information about users](User-GetUsers.ps1)
- [Create a new user](User-CreateUser.ps1)
- [Remove a user](User-RemoveUser.ps1)
- [Get information about roles](Role-GetRoles.ps1)
- [Create a new role](Role-CreateRole.ps1)
- [Remove a role](Role-RemoveRole.ps1)
## SDN Management Examples
- [Get information about SDN zones](SDN-GetZones.ps1)
- [Create a new SDN zone](SDN-CreateZone.ps1)
- [Remove an SDN zone](SDN-RemoveZone.ps1)
- [Get information about SDN VNets](SDN-GetVNets.ps1)
- [Create a new SDN VNet](SDN-CreateVNet.ps1)
- [Remove an SDN VNet](SDN-RemoveVNet.ps1)
## Template Management Examples
- [Get information about VM templates](Template-GetTemplates.ps1)
- [Create a new VM template](Template-CreateTemplate.ps1)
- [Remove a VM template](Template-RemoveTemplate.ps1)
- [Create a VM from a template](Template-CreateVMFromTemplate.ps1)
## IP Management Examples
- [Create a new IP pool](IP-CreatePool.ps1)
- [Get information about IP pools](IP-GetPools.ps1)
- [Clear an IP pool](IP-ClearPool.ps1)