From d0433ae21f0a145a03f262ba7cb6ba81c9a1d4bf Mon Sep 17 00:00:00 2001 From: Alphaeus Mote Date: Fri, 9 May 2025 12:57:29 -0400 Subject: [PATCH] Add automatic connection handling and Test-ProxmoxConnection cmdlet --- .../cmdlets/Connect-ProxmoxServer.md | 4 +- .../cmdlets/Disconnect-ProxmoxServer.md | 78 ++++++++++++ .../cmdlets/Test-ProxmoxConnection.md | 107 +++++++++++++++++ Module/PSProxmox.psd1 | 4 +- .../Cmdlets/ConnectProxmoxServerCmdlet.cs | 6 +- .../Cmdlets/DisconnectProxmoxServerCmdlet.cs | 12 ++ PSProxmox/Cmdlets/GetProxmoxVMCmdlet.cs | 13 +- PSProxmox/Cmdlets/ProxmoxCmdlet.cs | 61 ++++++++++ .../Cmdlets/TestProxmoxConnectionCmdlet.cs | 113 ++++++++++++++++++ PSProxmox/Session/ProxmoxConnection.cs | 9 ++ README.md | 82 +++++++------ release-notes.md | 33 +++++ 12 files changed, 471 insertions(+), 51 deletions(-) create mode 100644 Documentation/cmdlets/Disconnect-ProxmoxServer.md create mode 100644 Documentation/cmdlets/Test-ProxmoxConnection.md create mode 100644 PSProxmox/Cmdlets/ProxmoxCmdlet.cs create mode 100644 PSProxmox/Cmdlets/TestProxmoxConnectionCmdlet.cs create mode 100644 release-notes.md diff --git a/Documentation/cmdlets/Connect-ProxmoxServer.md b/Documentation/cmdlets/Connect-ProxmoxServer.md index 7cc6885..b9e4c59 100644 --- a/Documentation/cmdlets/Connect-ProxmoxServer.md +++ b/Documentation/cmdlets/Connect-ProxmoxServer.md @@ -238,7 +238,9 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ## Notes - This cmdlet must be called before using any other cmdlets in the PSProxmox module. -- The connection object is returned and should be stored in a variable for use with other cmdlets. +- The connection object is returned and automatically stored as the default connection. +- Other cmdlets will automatically use the default connection if no connection is specified. +- You can still store the connection in a variable and pass it explicitly to cmdlets if needed. - If you use the `-SkipCertificateValidation` parameter, the SSL certificate validation will be skipped, which is not recommended for production environments. ## Examples diff --git a/Documentation/cmdlets/Disconnect-ProxmoxServer.md b/Documentation/cmdlets/Disconnect-ProxmoxServer.md new file mode 100644 index 0000000..bf8879d --- /dev/null +++ b/Documentation/cmdlets/Disconnect-ProxmoxServer.md @@ -0,0 +1,78 @@ +# Disconnect-ProxmoxServer + +Disconnects from a Proxmox VE server. + +## Syntax + +```powershell +Disconnect-ProxmoxServer + -Connection + [] +``` + +## Description + +The `Disconnect-ProxmoxServer` cmdlet terminates a connection to a Proxmox VE server. If the connection being disconnected is the current default connection, it will also be cleared from the default connection. + +## Parameters + +### -Connection + +The connection to disconnect from. + +```yaml +Type: ProxmoxConnection +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### CommonParameters + +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## Inputs + +### PSProxmox.Session.ProxmoxConnection + +## Outputs + +### None + +## Notes + +- This cmdlet terminates the connection to the Proxmox VE server. +- If the connection being disconnected is the current default connection, it will also be cleared from the default connection. +- After disconnecting, you will need to call `Connect-ProxmoxServer` again to establish a new connection. + +## Examples + +### Example 1: Disconnect from a Proxmox VE server + +```powershell +$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential) +Disconnect-ProxmoxServer -Connection $connection +``` + +This example disconnects from a Proxmox VE server. + +### Example 2: Connect, use the default connection, and disconnect + +```powershell +Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential) +Get-ProxmoxVM # Uses the default connection automatically +$connection = Test-ProxmoxConnection -Detailed # Get the current connection +Disconnect-ProxmoxServer -Connection $connection +``` + +This example connects to a Proxmox VE server, uses the default connection with Get-ProxmoxVM, and then disconnects. + +## Related Links + +- [Connect-ProxmoxServer](Connect-ProxmoxServer.md) +- [Test-ProxmoxConnection](Test-ProxmoxConnection.md) diff --git a/Documentation/cmdlets/Test-ProxmoxConnection.md b/Documentation/cmdlets/Test-ProxmoxConnection.md new file mode 100644 index 0000000..1baa896 --- /dev/null +++ b/Documentation/cmdlets/Test-ProxmoxConnection.md @@ -0,0 +1,107 @@ +# Test-ProxmoxConnection + +Tests a connection to a Proxmox VE server. + +## Syntax + +```powershell +Test-ProxmoxConnection + [-Connection ] + [-Detailed] + [] +``` + +## Description + +The `Test-ProxmoxConnection` cmdlet tests if a connection to a Proxmox VE server is valid and active. If no connection is specified, the cmdlet will use the current default connection. + +## Parameters + +### -Connection + +The connection to test. If not specified, the current default connection will be used. + +```yaml +Type: ProxmoxConnection +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -Detailed + +Return detailed connection information instead of a boolean. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters + +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## Inputs + +### PSProxmox.Session.ProxmoxConnection + +## Outputs + +### System.Boolean + +Returns `$true` if the connection is valid and active, `$false` otherwise. + +### System.Management.Automation.PSObject + +When the `-Detailed` parameter is specified, returns a custom object with detailed connection information. + +## Notes + +- If no connection is specified and no default connection exists, the cmdlet will return an error. +- The cmdlet tests the connection by making a simple API call to the Proxmox VE server. + +## Examples + +### Example 1: Test the current connection + +```powershell +Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential) +Test-ProxmoxConnection +``` + +This example tests the current default connection. + +### Example 2: Test a specific connection + +```powershell +$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential) +Test-ProxmoxConnection -Connection $connection +``` + +This example tests a specific connection. + +### Example 3: Get detailed connection information + +```powershell +Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential) +Test-ProxmoxConnection -Detailed +``` + +This example returns detailed information about the current default connection. + +## Related Links + +- [Connect-ProxmoxServer](Connect-ProxmoxServer.md) +- [Disconnect-ProxmoxServer](Disconnect-ProxmoxServer.md) diff --git a/Module/PSProxmox.psd1 b/Module/PSProxmox.psd1 index 0095fb6..be3e74a 100644 --- a/Module/PSProxmox.psd1 +++ b/Module/PSProxmox.psd1 @@ -1,7 +1,7 @@ @{ RootModule = 'PSProxmox.psm1' NestedModules = @('bin\PSProxmox.dll') - ModuleVersion = '2025.05.07.1111' + ModuleVersion = '2025.05.09.1245' GUID = 'd24f0894-3d0c-4ef1-a41e-b273c3db86ad' Author = 'PSProxmox Team' CompanyName = 'PSProxmox' @@ -23,6 +23,7 @@ # Session Management 'Connect-ProxmoxServer', 'Disconnect-ProxmoxServer', + 'Test-ProxmoxConnection', # Node and VM Management 'Get-ProxmoxNode', @@ -103,3 +104,4 @@ + diff --git a/PSProxmox/Cmdlets/ConnectProxmoxServerCmdlet.cs b/PSProxmox/Cmdlets/ConnectProxmoxServerCmdlet.cs index 3603a16..d86d494 100644 --- a/PSProxmox/Cmdlets/ConnectProxmoxServerCmdlet.cs +++ b/PSProxmox/Cmdlets/ConnectProxmoxServerCmdlet.cs @@ -108,9 +108,11 @@ namespace PSProxmox.Cmdlets Realm, this); - // Return the actual connection object instead of the connection info + // Store the connection in a global variable for automatic use by other cmdlets + SessionState.PSVariable.Set(new PSVariable("DefaultProxmoxConnection", connection, ScopedItemOptions.AllScope)); + + // Return the connection object WriteObject(connection); - SessionState.PSVariable.Set(new PSVariable("ProxmoxConnection", connection, ScopedItemOptions.Private)); } catch (Exception ex) { diff --git a/PSProxmox/Cmdlets/DisconnectProxmoxServerCmdlet.cs b/PSProxmox/Cmdlets/DisconnectProxmoxServerCmdlet.cs index c29767d..5684ebf 100644 --- a/PSProxmox/Cmdlets/DisconnectProxmoxServerCmdlet.cs +++ b/PSProxmox/Cmdlets/DisconnectProxmoxServerCmdlet.cs @@ -34,6 +34,18 @@ namespace PSProxmox.Cmdlets } ProxmoxSession.Logout(Connection, this); + + // Clear the global connection variable if it matches the disconnected connection + var globalConnection = SessionState.PSVariable.GetValue("DefaultProxmoxConnection") as ProxmoxConnection; + if (globalConnection != null && + globalConnection.Server == Connection.Server && + globalConnection.Port == Connection.Port && + globalConnection.Username == Connection.Username) + { + SessionState.PSVariable.Remove("DefaultProxmoxConnection"); + WriteVerbose("Cleared default connection"); + } + WriteVerbose($"Disconnected from {Connection.Server}"); } catch (Exception ex) diff --git a/PSProxmox/Cmdlets/GetProxmoxVMCmdlet.cs b/PSProxmox/Cmdlets/GetProxmoxVMCmdlet.cs index d49eba6..a7e6b31 100644 --- a/PSProxmox/Cmdlets/GetProxmoxVMCmdlet.cs +++ b/PSProxmox/Cmdlets/GetProxmoxVMCmdlet.cs @@ -28,13 +28,8 @@ namespace PSProxmox.Cmdlets /// [Cmdlet(VerbsCommon.Get, "ProxmoxVM")] [OutputType(typeof(ProxmoxVM), typeof(string))] - public class GetProxmoxVMCmdlet : PSCmdlet + public class GetProxmoxVMCmdlet : ProxmoxCmdlet { - /// - /// The connection to the Proxmox VE server. - /// - [Parameter(Mandatory = true, Position = 0)] - public ProxmoxConnection Connection { get; set; } /// /// The ID of the virtual machine to retrieve. @@ -61,7 +56,9 @@ namespace PSProxmox.Cmdlets { try { - var client = new ProxmoxApiClient(Connection, this); + var connection = GetConnection(); + ValidateConnection(connection); + var client = new ProxmoxApiClient(connection, this); string response; if (VMID.HasValue) @@ -193,7 +190,7 @@ namespace PSProxmox.Cmdlets } catch (Exception ex) { - WriteError(new ErrorRecord(ex, "GetProxmoxVMError", ErrorCategory.OperationStopped, Connection)); + WriteError(new ErrorRecord(ex, "GetProxmoxVMError", ErrorCategory.OperationStopped, null)); } } } diff --git a/PSProxmox/Cmdlets/ProxmoxCmdlet.cs b/PSProxmox/Cmdlets/ProxmoxCmdlet.cs new file mode 100644 index 0000000..9130c15 --- /dev/null +++ b/PSProxmox/Cmdlets/ProxmoxCmdlet.cs @@ -0,0 +1,61 @@ +using System; +using System.Management.Automation; +using PSProxmox.Session; + +namespace PSProxmox.Cmdlets +{ + /// + /// Base class for Proxmox cmdlets that provides common functionality. + /// + public abstract class ProxmoxCmdlet : PSCmdlet + { + /// + /// The connection to the Proxmox VE server. If not specified, the current connection will be used. + /// + [Parameter(Mandatory = false, Position = 0)] + public ProxmoxConnection Connection { get; set; } + + /// + /// Gets the connection to use for the cmdlet. + /// + /// The connection to use. + protected ProxmoxConnection GetConnection() + { + // Use the specified connection if provided + if (Connection != null) + { + return Connection; + } + + // Otherwise, try to get the default connection + var defaultConnection = SessionState.PSVariable.GetValue("DefaultProxmoxConnection") as ProxmoxConnection; + if (defaultConnection == null) + { + throw new PSArgumentException( + "No connection specified and no default connection found. Use Connect-ProxmoxServer first.", + nameof(Connection)); + } + + return defaultConnection; + } + + /// + /// Validates that the connection is authenticated. + /// + /// The connection to validate. + protected void ValidateConnection(ProxmoxConnection connection) + { + if (connection == null) + { + throw new PSArgumentNullException(nameof(connection)); + } + + if (!connection.IsAuthenticated) + { + throw new PSArgumentException( + "The connection is not authenticated. Use Connect-ProxmoxServer first.", + nameof(connection)); + } + } + } +} diff --git a/PSProxmox/Cmdlets/TestProxmoxConnectionCmdlet.cs b/PSProxmox/Cmdlets/TestProxmoxConnectionCmdlet.cs new file mode 100644 index 0000000..1f50147 --- /dev/null +++ b/PSProxmox/Cmdlets/TestProxmoxConnectionCmdlet.cs @@ -0,0 +1,113 @@ +using System; +using System.Management.Automation; +using PSProxmox.Client; +using PSProxmox.Session; + +namespace PSProxmox.Cmdlets +{ + /// + /// Tests a connection to a Proxmox VE server. + /// The Test-ProxmoxConnection cmdlet tests if a connection to a Proxmox VE server is valid and active. + /// + /// Test the current connection + /// Test-ProxmoxConnection + /// + /// + /// Test a specific connection + /// Test-ProxmoxConnection -Connection $connection + /// + /// + [Cmdlet(VerbsDiagnostic.Test, "ProxmoxConnection")] + [OutputType(typeof(bool))] + public class TestProxmoxConnectionCmdlet : PSCmdlet + { + /// + /// The connection to test. If not specified, the current connection will be used. + /// + [Parameter(Mandatory = false, Position = 0, ValueFromPipeline = true)] + public ProxmoxConnection Connection { get; set; } + + /// + /// Return detailed connection information instead of a boolean. + /// + [Parameter(Mandatory = false)] + public SwitchParameter Detailed { get; set; } + + /// + /// Processes the cmdlet. + /// + protected override void ProcessRecord() + { + try + { + // Get the connection from the global variable if not specified + if (Connection == null) + { + var globalConnection = SessionState.PSVariable.GetValue("DefaultProxmoxConnection") as ProxmoxConnection; + if (globalConnection == null) + { + WriteError(new ErrorRecord( + new Exception("No connection specified and no default connection found. Use Connect-ProxmoxServer first."), + "NoConnectionFound", + ErrorCategory.ConnectionError, + null)); + return; + } + Connection = globalConnection; + } + + // Test the connection by making a simple API call + try + { + var client = new ProxmoxApiClient(Connection, this); + string response = client.Get("version"); + + if (Detailed.IsPresent) + { + // Return detailed connection information + var connectionInfo = new PSObject(); + connectionInfo.Properties.Add(new PSNoteProperty("Server", Connection.Server)); + connectionInfo.Properties.Add(new PSNoteProperty("Port", Connection.Port)); + connectionInfo.Properties.Add(new PSNoteProperty("Username", Connection.Username)); + connectionInfo.Properties.Add(new PSNoteProperty("Realm", Connection.Realm)); + connectionInfo.Properties.Add(new PSNoteProperty("UseSSL", Connection.UseSSL)); + connectionInfo.Properties.Add(new PSNoteProperty("IsAuthenticated", Connection.IsAuthenticated)); + connectionInfo.Properties.Add(new PSNoteProperty("Status", "Connected")); + WriteObject(connectionInfo); + } + else + { + // Return a simple boolean + WriteObject(true); + } + } + catch (Exception ex) + { + if (Detailed.IsPresent) + { + // Return detailed connection information with error + var connectionInfo = new PSObject(); + connectionInfo.Properties.Add(new PSNoteProperty("Server", Connection.Server)); + connectionInfo.Properties.Add(new PSNoteProperty("Port", Connection.Port)); + connectionInfo.Properties.Add(new PSNoteProperty("Username", Connection.Username)); + connectionInfo.Properties.Add(new PSNoteProperty("Realm", Connection.Realm)); + connectionInfo.Properties.Add(new PSNoteProperty("UseSSL", Connection.UseSSL)); + connectionInfo.Properties.Add(new PSNoteProperty("IsAuthenticated", Connection.IsAuthenticated)); + connectionInfo.Properties.Add(new PSNoteProperty("Status", "Error")); + connectionInfo.Properties.Add(new PSNoteProperty("Error", ex.Message)); + WriteObject(connectionInfo); + } + else + { + // Return a simple boolean + WriteObject(false); + } + } + } + catch (Exception ex) + { + WriteError(new ErrorRecord(ex, "TestProxmoxConnectionError", ErrorCategory.ConnectionError, Connection)); + } + } + } +} diff --git a/PSProxmox/Session/ProxmoxConnection.cs b/PSProxmox/Session/ProxmoxConnection.cs index cb59a60..8c63a63 100644 --- a/PSProxmox/Session/ProxmoxConnection.cs +++ b/PSProxmox/Session/ProxmoxConnection.cs @@ -93,5 +93,14 @@ namespace PSProxmox.Session }; return connection; } + + /// + /// Returns a string representation of the connection. + /// + /// A string representation of the connection. + public override string ToString() + { + return $"Proxmox Connection: {Username}@{Realm} on {Server}:{Port} ({(IsAuthenticated ? "Authenticated" : "Not Authenticated")})"; + } } } diff --git a/README.md b/README.md index 4988250..2db5ecc 100644 --- a/README.md +++ b/README.md @@ -50,24 +50,27 @@ cd PSProxmox ```powershell # 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" # Connect using a credential object $credential = Get-Credential -$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Credential $credential -Realm "pam" +Connect-ProxmoxServer -Server "proxmox.example.com" -Credential $credential -Realm "pam" + +# Test the connection +Test-ProxmoxConnection -Detailed ``` ### Managing Virtual Machines ```powershell -# Get all VMs -$vms = Get-ProxmoxVM -Connection $connection +# Get all VMs (uses the default connection automatically) +$vms = Get-ProxmoxVM # Get a specific VM -$vm = Get-ProxmoxVM -Connection $connection -VMID 100 +$vm = Get-ProxmoxVM -VMID 100 # Create a new VM -$vm = New-ProxmoxVM -Connection $connection -Node "pve1" -Name "test-vm" -Memory 2048 -Cores 2 -DiskSize 32 -Start +$vm = New-ProxmoxVM -Node "pve1" -Name "test-vm" -Memory 2048 -Cores 2 -DiskSize 32 -Start # Create a new VM using the builder pattern $builder = New-ProxmoxVMBuilder -Name "web-server" @@ -78,125 +81,125 @@ $builder.WithMemory(4096) .WithIPConfig("192.168.1.10/24", "192.168.1.1") .WithStart($true) -$vm = New-ProxmoxVM -Connection $connection -Node "pve1" -Builder $builder +$vm = New-ProxmoxVM -Node "pve1" -Builder $builder # Start, stop, and restart VMs -Start-ProxmoxVM -Connection $connection -Node "pve1" -VMID 100 -Stop-ProxmoxVM -Connection $connection -Node "pve1" -VMID 100 -Restart-ProxmoxVM -Connection $connection -Node "pve1" -VMID 100 +Start-ProxmoxVM -Node "pve1" -VMID 100 +Stop-ProxmoxVM -Node "pve1" -VMID 100 +Restart-ProxmoxVM -Node "pve1" -VMID 100 # Remove a VM -Remove-ProxmoxVM -Connection $connection -Node "pve1" -VMID 100 -Confirm:$false +Remove-ProxmoxVM -Node "pve1" -VMID 100 -Confirm:$false ``` ### Managing Templates ```powershell # Create a template from an existing VM -$template = New-ProxmoxVMTemplate -Connection $connection -VMID 100 -Name "Ubuntu-Template" -Description "Ubuntu 20.04 Template" +$template = New-ProxmoxVMTemplate -VMID 100 -Name "Ubuntu-Template" -Description "Ubuntu 20.04 Template" # Get all templates $templates = Get-ProxmoxVMTemplate # Create a VM from a template -$vm = New-ProxmoxVMFromTemplate -Connection $connection -Node "pve1" -TemplateName "Ubuntu-Template" -Name "web01" -Start +$vm = New-ProxmoxVMFromTemplate -Node "pve1" -TemplateName "Ubuntu-Template" -Name "web01" -Start # Create multiple VMs from a template -$vms = New-ProxmoxVMFromTemplate -Connection $connection -Node "pve1" -TemplateName "Ubuntu-Template" -Prefix "web" -Count 3 -Start +$vms = New-ProxmoxVMFromTemplate -Node "pve1" -TemplateName "Ubuntu-Template" -Prefix "web" -Count 3 -Start ``` ### Managing Storage ```powershell # Get all storage -$storage = Get-ProxmoxStorage -Connection $connection +$storage = Get-ProxmoxStorage # Get storage on a specific node -$storage = Get-ProxmoxStorage -Connection $connection -Node "pve1" +$storage = Get-ProxmoxStorage -Node "pve1" # Create a new storage -$storage = New-ProxmoxStorage -Connection $connection -Name "backup" -Type "dir" -Path "/mnt/backup" -Content "backup,iso" +$storage = New-ProxmoxStorage -Name "backup" -Type "dir" -Path "/mnt/backup" -Content "backup,iso" # Remove a storage -Remove-ProxmoxStorage -Connection $connection -Name "backup" -Confirm:$false +Remove-ProxmoxStorage -Name "backup" -Confirm:$false ``` ### Managing Networks ```powershell # Get all network interfaces on a node -$networks = Get-ProxmoxNetwork -Connection $connection -Node "pve1" +$networks = Get-ProxmoxNetwork -Node "pve1" # Create a new bridge interface -$network = New-ProxmoxNetwork -Connection $connection -Node "pve1" -Interface "vmbr1" -Type "bridge" -BridgePorts "eth1" -Method "static" -Address "192.168.2.1" -Netmask "255.255.255.0" -Autostart +$network = New-ProxmoxNetwork -Node "pve1" -Interface "vmbr1" -Type "bridge" -BridgePorts "eth1" -Method "static" -Address "192.168.2.1" -Netmask "255.255.255.0" -Autostart # Remove a network interface -Remove-ProxmoxNetwork -Connection $connection -Node "pve1" -Interface "vmbr1" -Confirm:$false +Remove-ProxmoxNetwork -Node "pve1" -Interface "vmbr1" -Confirm:$false ``` ### Managing Users and Roles ```powershell # Get all users -$users = Get-ProxmoxUser -Connection $connection +$users = Get-ProxmoxUser # Create a new user $securePassword = ConvertTo-SecureString "password" -AsPlainText -Force -$user = New-ProxmoxUser -Connection $connection -Username "john" -Realm "pam" -Password $securePassword -FirstName "John" -LastName "Doe" -Email "john.doe@example.com" +$user = New-ProxmoxUser -Username "john" -Realm "pam" -Password $securePassword -FirstName "John" -LastName "Doe" -Email "john.doe@example.com" # Remove a user -Remove-ProxmoxUser -Connection $connection -UserID "john@pam" -Confirm:$false +Remove-ProxmoxUser -UserID "john@pam" -Confirm:$false # Get all roles -$roles = Get-ProxmoxRole -Connection $connection +$roles = Get-ProxmoxRole # Create a new role -$role = New-ProxmoxRole -Connection $connection -RoleID "Developer" -Privileges "VM.Allocate", "VM.Config.Disk", "VM.Config.CPU", "VM.PowerMgmt" +$role = New-ProxmoxRole -RoleID "Developer" -Privileges "VM.Allocate", "VM.Config.Disk", "VM.Config.CPU", "VM.PowerMgmt" # Remove a role -Remove-ProxmoxRole -Connection $connection -RoleID "Developer" -Confirm:$false +Remove-ProxmoxRole -RoleID "Developer" -Confirm:$false ``` ### Managing SDN ```powershell # Get all SDN zones -$zones = Get-ProxmoxSDNZone -Connection $connection +$zones = Get-ProxmoxSDNZone # Create a new SDN zone -$zone = New-ProxmoxSDNZone -Connection $connection -Zone "zone1" -Type "vlan" -Bridge "vmbr0" +$zone = New-ProxmoxSDNZone -Zone "zone1" -Type "vlan" -Bridge "vmbr0" # Remove an SDN zone -Remove-ProxmoxSDNZone -Connection $connection -Zone "zone1" -Confirm:$false +Remove-ProxmoxSDNZone -Zone "zone1" -Confirm:$false # Get all SDN VNets -$vnets = Get-ProxmoxSDNVnet -Connection $connection +$vnets = Get-ProxmoxSDNVnet # Create a new SDN VNet -$vnet = New-ProxmoxSDNVnet -Connection $connection -VNet "vnet1" -Zone "zone1" -IPv4 "192.168.1.0/24" -Gateway "192.168.1.1" +$vnet = New-ProxmoxSDNVnet -VNet "vnet1" -Zone "zone1" -IPv4 "192.168.1.0/24" -Gateway "192.168.1.1" # Remove an SDN VNet -Remove-ProxmoxSDNVnet -Connection $connection -VNet "vnet1" -Confirm:$false +Remove-ProxmoxSDNVnet -VNet "vnet1" -Confirm:$false ``` ### Managing Clusters ```powershell # Get cluster information -$cluster = Get-ProxmoxCluster -Connection $connection +$cluster = Get-ProxmoxCluster # Join a node to a cluster $securePassword = ConvertTo-SecureString "password" -AsPlainText -Force -Join-ProxmoxCluster -Connection $connection -ClusterName "cluster1" -HostName "pve1" -Password $securePassword +Join-ProxmoxCluster -ClusterName "cluster1" -HostName "pve1" -Password $securePassword # Leave a cluster -Leave-ProxmoxCluster -Connection $connection -Force +Leave-ProxmoxCluster -Force # Create a cluster backup -$backup = New-ProxmoxClusterBackup -Connection $connection -Compress -Wait +$backup = New-ProxmoxClusterBackup -Compress -Wait # Restore a cluster backup -Restore-ProxmoxClusterBackup -Connection $connection -BackupID "vzdump-cluster-2023_04_28-12_00_00.vma.lzo" -Force -Wait +Restore-ProxmoxClusterBackup -BackupID "vzdump-cluster-2023_04_28-12_00_00.vma.lzo" -Force -Wait ``` ### Managing IP Addresses @@ -218,7 +221,8 @@ Clear-ProxmoxIPPool -Name "Production" ## Disconnecting ```powershell -# Disconnect from the server +# Get the current connection and disconnect from the server +$connection = Test-ProxmoxConnection -Detailed Disconnect-ProxmoxServer -Connection $connection ``` diff --git a/release-notes.md b/release-notes.md new file mode 100644 index 0000000..8f468e1 --- /dev/null +++ b/release-notes.md @@ -0,0 +1,33 @@ +# PSProxmox v2025.05.09.1246 Release Notes + +## New Features + +### VM Creation Enhancements +- Added padded counter functionality for multi-VM creation (e.g., "Prefix-00001") +- Added AutoSMBIOS capability parameters for setting realistic hardware information +- Added Microsoft VMBIOS profile for SMBIOS settings +- Enhanced existing manufacturer profiles with more business-class workstations and servers +- Improved serial number generation for major non-VM vendors + +### SMBIOS Improvements +- Only generate random UUIDs if one is not already present +- Added more realistic hardware information for Dell, HP, Lenovo, and Microsoft devices +- Added support for both server and workstation profiles for each manufacturer + +## Documentation +- Added comprehensive documentation for the new features +- Added example scripts for using padded counters and SMBIOS settings +- Updated existing documentation to reflect the new capabilities + +## Bug Fixes +- Fixed module loading issues by using PSM1 file and NestedModules +- Fixed type mismatch between ProxmoxConnectionInfo and ProxmoxConnection classes + +## Installation +1. Download the ZIP file +2. Extract the contents to a directory in your PowerShell module path +3. Import the module using `Import-Module PSProxmox` + +## Requirements +- PowerShell 5.1 or later +- Windows PowerShell or PowerShell Core