mirror of
https://github.com/Grace-Solutions/PSProxmox.git
synced 2026-08-07 22:03:15 +00:00
Add automatic connection handling and Test-ProxmoxConnection cmdlet
This commit is contained in:
@@ -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)
|
||||
@@ -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 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -28,13 +28,8 @@ namespace PSProxmox.Cmdlets
|
||||
/// </summary>
|
||||
[Cmdlet(VerbsCommon.Get, "ProxmoxVM")]
|
||||
[OutputType(typeof(ProxmoxVM), typeof(string))]
|
||||
public class GetProxmoxVMCmdlet : PSCmdlet
|
||||
public class GetProxmoxVMCmdlet : ProxmoxCmdlet
|
||||
{
|
||||
/// <summary>
|
||||
/// <para type="description">The connection to the Proxmox VE server.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = true, Position = 0)]
|
||||
public ProxmoxConnection Connection { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">The ID of the virtual machine to retrieve.</para>
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using PSProxmox.Session;
|
||||
|
||||
namespace PSProxmox.Cmdlets
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for Proxmox cmdlets that provides common functionality.
|
||||
/// </summary>
|
||||
public abstract class ProxmoxCmdlet : PSCmdlet
|
||||
{
|
||||
/// <summary>
|
||||
/// <para type="description">The connection to the Proxmox VE server. If not specified, the current connection will be used.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false, Position = 0)]
|
||||
public ProxmoxConnection Connection { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the connection to use for the cmdlet.
|
||||
/// </summary>
|
||||
/// <returns>The connection to use.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates that the connection is authenticated.
|
||||
/// </summary>
|
||||
/// <param name="connection">The connection to validate.</param>
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using PSProxmox.Client;
|
||||
using PSProxmox.Session;
|
||||
|
||||
namespace PSProxmox.Cmdlets
|
||||
{
|
||||
/// <summary>
|
||||
/// <para type="synopsis">Tests a connection to a Proxmox VE server.</para>
|
||||
/// <para type="description">The Test-ProxmoxConnection cmdlet tests if a connection to a Proxmox VE server is valid and active.</para>
|
||||
/// <example>
|
||||
/// <para>Test the current connection</para>
|
||||
/// <code>Test-ProxmoxConnection</code>
|
||||
/// </example>
|
||||
/// <example>
|
||||
/// <para>Test a specific connection</para>
|
||||
/// <code>Test-ProxmoxConnection -Connection $connection</code>
|
||||
/// </example>
|
||||
/// </summary>
|
||||
[Cmdlet(VerbsDiagnostic.Test, "ProxmoxConnection")]
|
||||
[OutputType(typeof(bool))]
|
||||
public class TestProxmoxConnectionCmdlet : PSCmdlet
|
||||
{
|
||||
/// <summary>
|
||||
/// <para type="description">The connection to test. If not specified, the current connection will be used.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false, Position = 0, ValueFromPipeline = true)]
|
||||
public ProxmoxConnection Connection { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">Return detailed connection information instead of a boolean.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false)]
|
||||
public SwitchParameter Detailed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Processes the cmdlet.
|
||||
/// </summary>
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,5 +93,14 @@ namespace PSProxmox.Session
|
||||
};
|
||||
return connection;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string representation of the connection.
|
||||
/// </summary>
|
||||
/// <returns>A string representation of the connection.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Proxmox Connection: {Username}@{Realm} on {Server}:{Port} ({(IsAuthenticated ? "Authenticated" : "Not Authenticated")})";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
```
|
||||
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user