Add automatic connection handling and Test-ProxmoxConnection cmdlet

This commit is contained in:
Alphaeus Mote
2025-05-09 14:35:20 -04:00
parent d0433ae21f
commit 7478796d16
7 changed files with 55 additions and 43 deletions
@@ -6,17 +6,17 @@ 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"
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" `
$vms = New-ProxmoxVMFromTemplate -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" `
$vms = New-ProxmoxVMFromTemplate -Node "pve1" -TemplateName "Ubuntu-Template" `
-Prefix "db" -Count 2 -StartIndex 1 -Memory 4096 -Cores 2 -DiskSize 50 -Start
# Display the VM information
@@ -29,11 +29,12 @@ if (-not (Get-ProxmoxIPPool -Name "Production")) {
}
# Create the VMs with IP addresses from the pool
$vms = New-ProxmoxVMFromTemplate -Connection $connection -Node "pve1" -TemplateName "Ubuntu-Template" `
$vms = New-ProxmoxVMFromTemplate -Node "pve1" -TemplateName "Ubuntu-Template" `
-Prefix "app" -Count 5 -IPPool "Production" -Start
# Display the VM information
$vms
# Disconnect from the server when done
# Get the current connection and disconnect from the server when done
$connection = Test-ProxmoxConnection -Detailed
Disconnect-ProxmoxServer -Connection $connection
@@ -6,10 +6,10 @@ 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"
Connect-ProxmoxServer -Server "proxmox.example.com" -Credential $credential -Realm "pam"
# Method 1: Create multiple VMs with padded counters
$vms = New-ProxmoxVMFromTemplate -Connection $connection -Node "pve1" -TemplateName "Ubuntu-Template" `
$vms = New-ProxmoxVMFromTemplate -Node "pve1" -TemplateName "Ubuntu-Template" `
-Prefix "web-" -Count 3 -CounterDigits 3 -Start
# Display the VM information
@@ -17,7 +17,7 @@ Write-Host "Created VMs with padded counters:"
$vms | Select-Object Name, VMID, Status | Format-Table
# Method 2: Create multiple VMs with padded counters and custom starting index
$vms = New-ProxmoxVMFromTemplate -Connection $connection -Node "pve1" -TemplateName "Ubuntu-Template" `
$vms = New-ProxmoxVMFromTemplate -Node "pve1" -TemplateName "Ubuntu-Template" `
-Prefix "db-" -Count 2 -StartIndex 10 -CounterDigits 4 -Memory 4096 -Cores 2 -Start
# Display the VM information
@@ -25,7 +25,7 @@ Write-Host "Created VMs with padded counters and custom starting index:"
$vms | Select-Object Name, VMID, Status | Format-Table
# Method 3: Create multiple VMs with automatic SMBIOS settings
$vms = New-ProxmoxVMFromTemplate -Connection $connection -Node "pve1" -TemplateName "Windows-Template" `
$vms = New-ProxmoxVMFromTemplate -Node "pve1" -TemplateName "Windows-Template" `
-Prefix "win-" -Count 3 -CounterDigits 2 -AutomaticSMBIOS -SMBIOSProfile "Dell" -Start
# Display the VM information
@@ -36,21 +36,22 @@ $vms | Select-Object Name, VMID, Status | Format-Table
$manufacturers = @("Dell", "HP", "Lenovo", "Microsoft")
$count = $manufacturers.Count
$vms = New-ProxmoxVMFromTemplate -Connection $connection -Node "pve1" -TemplateName "Windows-Template" `
$vms = New-ProxmoxVMFromTemplate -Node "pve1" -TemplateName "Windows-Template" `
-Prefix "test-" -Count $count -CounterDigits 2 -Start
# Update each VM with a different SMBIOS profile
for ($i = 0; $i -lt $count; $i++) {
$profile = $manufacturers[$i]
$vmid = $vms[$i].VMID
Write-Host "Setting $profile SMBIOS profile for VM $vmid..."
Set-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID $vmid -UseProfile -Profile $profile
Set-ProxmoxVMSMBIOS -Node "pve1" -VMID $vmid -UseProfile -Profile $profile
}
# Display the VM information
Write-Host "Created VMs with different SMBIOS profiles:"
$vms | Select-Object Name, VMID, Status | Format-Table
# Disconnect from the server when done
# Get the current connection and disconnect from the server when done
$connection = Test-ProxmoxConnection -Detailed
Disconnect-ProxmoxServer -Connection $connection
@@ -6,7 +6,7 @@ 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"
Connect-ProxmoxServer -Server "proxmox.example.com" -Credential $credential -Realm "pam"
# Create a VM builder
$builder = New-ProxmoxVMBuilder -Name "web-server"
@@ -21,8 +21,8 @@ $builder.WithMemory(4096) # 4 GB of memory
.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
# Create the VM using the builder (uses the default connection automatically)
$vm = New-ProxmoxVM -Node "pve1" -Builder $builder
# Display the VM information
$vm
@@ -46,10 +46,11 @@ $builder.WithMemory(8192) # 8 GB of memory
.WithStart($true) # Start the VM after creation
# Create the VM using the builder
$vm = New-ProxmoxVM -Connection $connection -Node "pve1" -Builder $builder
$vm = New-ProxmoxVM -Node "pve1" -Builder $builder
# Display the VM information
$vm
# Disconnect from the server when done
# Get the current connection and disconnect from the server when done
$connection = Test-ProxmoxConnection -Detailed
Disconnect-ProxmoxServer -Connection $connection
+10 -6
View File
@@ -6,22 +6,26 @@ 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"
Connect-ProxmoxServer -Server "proxmox.example.com" -Username "root" -Password $securePassword -Realm "pam"
# Test the connection
Test-ProxmoxConnection -Detailed
# 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"
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
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
Connect-ProxmoxServer -Server "proxmox.example.com" -Username "root" -Password $securePassword -Realm "pam" -SkipCertificateValidation $true
# Display the connection information
$connection
# Get the current connection details
$connection = Test-ProxmoxConnection -Detailed
Write-Host "Connected to $($connection.Server) as $($connection.Username)@$($connection.Realm)"
# Disconnect from the server when done
Disconnect-ProxmoxServer -Connection $connection
+10 -6
View File
@@ -6,16 +6,19 @@ 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"
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
# Test the connection
Test-ProxmoxConnection
# Method 1: Create a basic VM (uses the default connection automatically)
$vm = New-ProxmoxVM -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" `
$vm = New-ProxmoxVM -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
@@ -24,11 +27,12 @@ $vm = New-ProxmoxVM -Connection $connection -Node "pve1" -Name "web-server" `
$vm
# Method 3: Create a VM with a specific ID
$vm = New-ProxmoxVM -Connection $connection -Node "pve1" -Name "db-server" -VMID 200 `
$vm = New-ProxmoxVM -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
# Get the current connection and disconnect from the server when done
$connection = Test-ProxmoxConnection -Detailed
Disconnect-ProxmoxServer -Connection $connection
+12 -11
View File
@@ -6,13 +6,13 @@ 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"
Connect-ProxmoxServer -Server "proxmox.example.com" -Credential $credential -Realm "pam"
# Example 1: Create a VM with automatic SMBIOS settings using a specific manufacturer profile
$vm1 = New-ProxmoxVM -Connection $connection -Node "pve1" -Name "dell-server" -Memory 2048 -Cores 2 -DiskSize 32 -AutomaticSMBIOS -SMBIOSProfile "Dell"
$vm1 = New-ProxmoxVM -Node "pve1" -Name "dell-server" -Memory 2048 -Cores 2 -DiskSize 32 -AutomaticSMBIOS -SMBIOSProfile "Dell"
# Example 2: Create a VM with automatic SMBIOS settings using a random manufacturer profile
$vm2 = New-ProxmoxVM -Connection $connection -Node "pve1" -Name "random-server" -Memory 2048 -Cores 2 -DiskSize 32 -AutomaticSMBIOS -SMBIOSProfile "Random"
$vm2 = New-ProxmoxVM -Node "pve1" -Name "random-server" -Memory 2048 -Cores 2 -DiskSize 32 -AutomaticSMBIOS -SMBIOSProfile "Random"
# Example 3: Create a VM using the builder pattern with automatic SMBIOS settings
$builder = New-ProxmoxVMBuilder -Name "hp-server" -AutomaticSMBIOS -SMBIOSProfile "HP"
@@ -21,7 +21,7 @@ $builder.WithMemory(4096)
.WithDisk(50, "local-lvm")
.WithNetwork("virtio", "vmbr0")
.WithStart($true)
$vm3 = New-ProxmoxVM -Connection $connection -Node "pve1" -Builder $builder
$vm3 = New-ProxmoxVM -Node "pve1" -Builder $builder
# Example 4: Create a VM using the builder pattern with manual SMBIOS settings
$builder = New-ProxmoxVMBuilder -Name "custom-server"
@@ -34,10 +34,10 @@ $builder.WithMemory(4096)
.WithSMBIOSVersion("1.0")
.WithSMBIOSSerial("CUSTOM123")
.WithStart($true)
$vm4 = New-ProxmoxVM -Connection $connection -Node "pve1" -Builder $builder
$vm4 = New-ProxmoxVM -Node "pve1" -Builder $builder
# Example 5: Get SMBIOS settings for an existing VM
$smbios = Get-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100
$smbios = Get-ProxmoxVMSMBIOS -Node "pve1" -VMID 100
Write-Host "Current SMBIOS settings for VM 100:"
Write-Host "Manufacturer: $($smbios.Manufacturer)"
Write-Host "Product: $($smbios.Product)"
@@ -47,10 +47,10 @@ Write-Host "Family: $($smbios.Family)"
Write-Host "UUID: $($smbios.UUID)"
# Example 6: Update SMBIOS settings for an existing VM using individual parameters
Set-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100 -Manufacturer "Lenovo" -Product "ThinkSystem SR650" -Serial "LENOVO123"
Set-ProxmoxVMSMBIOS -Node "pve1" -VMID 100 -Manufacturer "Lenovo" -Product "ThinkSystem SR650" -Serial "LENOVO123"
# Example 7: Update SMBIOS settings for an existing VM using a manufacturer profile
Set-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 101 -UseProfile -Profile "VMware" -PassThru
Set-ProxmoxVMSMBIOS -Node "pve1" -VMID 101 -UseProfile -Profile "VMware" -PassThru
# Example 8: Create a VM with SMBIOS settings that mimic a physical server for licensing purposes
$builder = New-ProxmoxVMBuilder -Name "license-server" -AutomaticSMBIOS -SMBIOSProfile "Dell"
@@ -59,7 +59,7 @@ $builder.WithMemory(8192)
.WithDisk(100, "local-lvm")
.WithNetwork("virtio", "vmbr0")
.WithStart($true)
$vm5 = New-ProxmoxVM -Connection $connection -Node "pve1" -Builder $builder
$vm5 = New-ProxmoxVM -Node "pve1" -Builder $builder
# Example 9: Create a VM with Microsoft Surface SMBIOS settings
$builder = New-ProxmoxVMBuilder -Name "surface-pro" -AutomaticSMBIOS -SMBIOSProfile "Microsoft"
@@ -68,7 +68,8 @@ $builder.WithMemory(4096)
.WithDisk(50, "local-lvm")
.WithNetwork("virtio", "vmbr0")
.WithStart($true)
$vm6 = New-ProxmoxVM -Connection $connection -Node "pve1" -Builder $builder
$vm6 = New-ProxmoxVM -Node "pve1" -Builder $builder
# Disconnect from the server when done
# Get the current connection and disconnect from the server when done
$connection = Test-ProxmoxConnection -Detailed
Disconnect-ProxmoxServer -Connection $connection
+2 -2
View File
@@ -1,7 +1,7 @@
@{
RootModule = 'PSProxmox.psm1'
NestedModules = @('bin\PSProxmox.dll')
ModuleVersion = '2025.05.09.1245'
ModuleVersion = '2025.05.10.1000'
GUID = 'd24f0894-3d0c-4ef1-a41e-b273c3db86ad'
Author = 'PSProxmox Team'
CompanyName = 'PSProxmox'
@@ -85,7 +85,7 @@
Tags = @('Proxmox', 'VirtualMachine', 'Cluster', 'Management')
LicenseUri = 'https://github.com/freedbygrace/PSProxmox/blob/main/LICENSE'
ProjectUri = 'https://github.com/freedbygrace/PSProxmox'
ReleaseNotes = 'Initial release of PSProxmox module. See https://github.com/freedbygrace/PSProxmox/releases/tag/v2025.04.28.1902'
ReleaseNotes = 'Added automatic connection handling and Test-ProxmoxConnection cmdlet. See https://github.com/freedbygrace/PSProxmox/releases/tag/v2025.05.10.1000'
}
}
}