Add automatic connection handling and Test-ProxmoxConnection cmdlet

This commit is contained in:
Alphaeus Mote
2025-05-09 12:57:29 -04:00
parent f906f41364
commit d0433ae21f
12 changed files with 471 additions and 51 deletions
@@ -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
@@ -0,0 +1,78 @@
# Disconnect-ProxmoxServer
Disconnects from a Proxmox VE server.
## Syntax
```powershell
Disconnect-ProxmoxServer
-Connection <ProxmoxConnection>
[<CommonParameters>]
```
## 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)
@@ -0,0 +1,107 @@
# Test-ProxmoxConnection
Tests a connection to a Proxmox VE server.
## Syntax
```powershell
Test-ProxmoxConnection
[-Connection <ProxmoxConnection>]
[-Detailed]
[<CommonParameters>]
```
## 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)