mirror of
https://github.com/Grace-Solutions/PSProxmox.git
synced 2026-08-18 18:46:18 +00:00
Add automatic connection handling and Test-ProxmoxConnection cmdlet
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user