mirror of
https://github.com/Grace-Solutions/PSProxmox.git
synced 2026-08-08 06:13:15 +00:00
Add SMBIOS functionality with manufacturer profiles
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
# Get-ProxmoxVMSMBIOS
|
||||
|
||||
Gets the SMBIOS settings for a Proxmox VM.
|
||||
|
||||
## Syntax
|
||||
|
||||
```powershell
|
||||
Get-ProxmoxVMSMBIOS
|
||||
-Connection <ProxmoxConnection>
|
||||
-Node <String>
|
||||
-VMID <Int32>
|
||||
[-RawJson]
|
||||
[<CommonParameters>]
|
||||
```
|
||||
|
||||
## Description
|
||||
|
||||
The `Get-ProxmoxVMSMBIOS` cmdlet retrieves the SMBIOS (System Management BIOS) settings for a virtual machine in Proxmox VE. SMBIOS settings allow you to customize hardware identification information that's presented to the guest operating system.
|
||||
|
||||
## Parameters
|
||||
|
||||
### -Connection
|
||||
|
||||
The connection to the Proxmox VE server.
|
||||
|
||||
```yaml
|
||||
Type: ProxmoxConnection
|
||||
Parameter Sets: (All)
|
||||
Aliases:
|
||||
|
||||
Required: True
|
||||
Position: 0
|
||||
Default value: None
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### -Node
|
||||
|
||||
The node where the VM is located.
|
||||
|
||||
```yaml
|
||||
Type: String
|
||||
Parameter Sets: (All)
|
||||
Aliases:
|
||||
|
||||
Required: True
|
||||
Position: 1
|
||||
Default value: None
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### -VMID
|
||||
|
||||
The ID of the VM.
|
||||
|
||||
```yaml
|
||||
Type: Int32
|
||||
Parameter Sets: (All)
|
||||
Aliases:
|
||||
|
||||
Required: True
|
||||
Position: 2
|
||||
Default value: None
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### -RawJson
|
||||
|
||||
Return the raw JSON response from the Proxmox API instead of a PowerShell object.
|
||||
|
||||
```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
|
||||
|
||||
### None
|
||||
|
||||
## Outputs
|
||||
|
||||
### PSProxmox.Models.ProxmoxVMSMBIOS
|
||||
|
||||
Returns a ProxmoxVMSMBIOS object containing the SMBIOS settings for the VM.
|
||||
|
||||
## Notes
|
||||
|
||||
- SMBIOS settings can be useful for software licensing that's tied to hardware identifiers
|
||||
- These settings can also help with VM migration between different hypervisors
|
||||
- Some applications may require specific hardware information to function properly
|
||||
|
||||
## Examples
|
||||
|
||||
### Example 1: Get SMBIOS settings for a VM
|
||||
|
||||
```powershell
|
||||
$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential)
|
||||
Get-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100
|
||||
```
|
||||
|
||||
This example retrieves the SMBIOS settings for VM 100 on node pve1.
|
||||
|
||||
### Example 2: Get SMBIOS settings and display specific properties
|
||||
|
||||
```powershell
|
||||
$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential)
|
||||
$smbios = Get-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100
|
||||
$smbios | Select-Object Manufacturer, Product, Serial
|
||||
```
|
||||
|
||||
This example retrieves the SMBIOS settings for VM 100 and displays only the manufacturer, product, and serial number.
|
||||
|
||||
### Example 3: Get SMBIOS settings as raw JSON
|
||||
|
||||
```powershell
|
||||
$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential)
|
||||
Get-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100 -RawJson
|
||||
```
|
||||
|
||||
This example retrieves the SMBIOS settings for VM 100 as raw JSON.
|
||||
|
||||
## Related Links
|
||||
|
||||
- [Set-ProxmoxVMSMBIOS](Set-ProxmoxVMSMBIOS.md)
|
||||
- [New-ProxmoxVMBuilder](New-ProxmoxVMBuilder.md)
|
||||
- [New-ProxmoxVM](New-ProxmoxVM.md)
|
||||
@@ -0,0 +1,310 @@
|
||||
# Set-ProxmoxVMSMBIOS
|
||||
|
||||
Sets the SMBIOS settings for a Proxmox VM.
|
||||
|
||||
## Syntax
|
||||
|
||||
```powershell
|
||||
Set-ProxmoxVMSMBIOS
|
||||
-Connection <ProxmoxConnection>
|
||||
-Node <String>
|
||||
-VMID <Int32>
|
||||
-SMBIOS <ProxmoxVMSMBIOS>
|
||||
[-PassThru]
|
||||
[-WhatIf]
|
||||
[-Confirm]
|
||||
[<CommonParameters>]
|
||||
```
|
||||
|
||||
```powershell
|
||||
Set-ProxmoxVMSMBIOS
|
||||
-Connection <ProxmoxConnection>
|
||||
-Node <String>
|
||||
-VMID <Int32>
|
||||
[-Manufacturer <String>]
|
||||
[-Product <String>]
|
||||
[-Version <String>]
|
||||
[-Serial <String>]
|
||||
[-Family <String>]
|
||||
[-UUID <String>]
|
||||
[-PassThru]
|
||||
[-WhatIf]
|
||||
[-Confirm]
|
||||
[<CommonParameters>]
|
||||
```
|
||||
|
||||
## Description
|
||||
|
||||
The `Set-ProxmoxVMSMBIOS` cmdlet sets the SMBIOS (System Management BIOS) settings for a virtual machine in Proxmox VE. SMBIOS settings allow you to customize hardware identification information that's presented to the guest operating system.
|
||||
|
||||
## Parameters
|
||||
|
||||
### -Connection
|
||||
|
||||
The connection to the Proxmox VE server.
|
||||
|
||||
```yaml
|
||||
Type: ProxmoxConnection
|
||||
Parameter Sets: (All)
|
||||
Aliases:
|
||||
|
||||
Required: True
|
||||
Position: 0
|
||||
Default value: None
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### -Node
|
||||
|
||||
The node where the VM is located.
|
||||
|
||||
```yaml
|
||||
Type: String
|
||||
Parameter Sets: (All)
|
||||
Aliases:
|
||||
|
||||
Required: True
|
||||
Position: 1
|
||||
Default value: None
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### -VMID
|
||||
|
||||
The ID of the VM.
|
||||
|
||||
```yaml
|
||||
Type: Int32
|
||||
Parameter Sets: (All)
|
||||
Aliases:
|
||||
|
||||
Required: True
|
||||
Position: 2
|
||||
Default value: None
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### -SMBIOS
|
||||
|
||||
The SMBIOS settings object.
|
||||
|
||||
```yaml
|
||||
Type: ProxmoxVMSMBIOS
|
||||
Parameter Sets: SMBIOSObject
|
||||
Aliases:
|
||||
|
||||
Required: True
|
||||
Position: Named
|
||||
Default value: None
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### -Manufacturer
|
||||
|
||||
The manufacturer information.
|
||||
|
||||
```yaml
|
||||
Type: String
|
||||
Parameter Sets: Individual
|
||||
Aliases:
|
||||
|
||||
Required: False
|
||||
Position: Named
|
||||
Default value: None
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### -Product
|
||||
|
||||
The product information.
|
||||
|
||||
```yaml
|
||||
Type: String
|
||||
Parameter Sets: Individual
|
||||
Aliases:
|
||||
|
||||
Required: False
|
||||
Position: Named
|
||||
Default value: None
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### -Version
|
||||
|
||||
The version information.
|
||||
|
||||
```yaml
|
||||
Type: String
|
||||
Parameter Sets: Individual
|
||||
Aliases:
|
||||
|
||||
Required: False
|
||||
Position: Named
|
||||
Default value: None
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### -Serial
|
||||
|
||||
The serial number.
|
||||
|
||||
```yaml
|
||||
Type: String
|
||||
Parameter Sets: Individual
|
||||
Aliases:
|
||||
|
||||
Required: False
|
||||
Position: Named
|
||||
Default value: None
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### -Family
|
||||
|
||||
The system family.
|
||||
|
||||
```yaml
|
||||
Type: String
|
||||
Parameter Sets: Individual
|
||||
Aliases:
|
||||
|
||||
Required: False
|
||||
Position: Named
|
||||
Default value: None
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### -UUID
|
||||
|
||||
The system UUID.
|
||||
|
||||
```yaml
|
||||
Type: String
|
||||
Parameter Sets: Individual
|
||||
Aliases:
|
||||
|
||||
Required: False
|
||||
Position: Named
|
||||
Default value: None
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### -PassThru
|
||||
|
||||
Return the updated SMBIOS settings.
|
||||
|
||||
```yaml
|
||||
Type: SwitchParameter
|
||||
Parameter Sets: (All)
|
||||
Aliases:
|
||||
|
||||
Required: False
|
||||
Position: Named
|
||||
Default value: False
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### -WhatIf
|
||||
|
||||
Shows what would happen if the cmdlet runs. The cmdlet is not run.
|
||||
|
||||
```yaml
|
||||
Type: SwitchParameter
|
||||
Parameter Sets: (All)
|
||||
Aliases: wi
|
||||
|
||||
Required: False
|
||||
Position: Named
|
||||
Default value: None
|
||||
Accept pipeline input: False
|
||||
Accept wildcard characters: False
|
||||
```
|
||||
|
||||
### -Confirm
|
||||
|
||||
Prompts you for confirmation before running the cmdlet.
|
||||
|
||||
```yaml
|
||||
Type: SwitchParameter
|
||||
Parameter Sets: (All)
|
||||
Aliases: cf
|
||||
|
||||
Required: False
|
||||
Position: Named
|
||||
Default value: None
|
||||
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
|
||||
|
||||
### None
|
||||
|
||||
## Outputs
|
||||
|
||||
### PSProxmox.Models.ProxmoxVMSMBIOS
|
||||
|
||||
Returns a ProxmoxVMSMBIOS object if -PassThru is specified.
|
||||
|
||||
## Notes
|
||||
|
||||
- SMBIOS settings can be useful for software licensing that's tied to hardware identifiers
|
||||
- These settings can also help with VM migration between different hypervisors
|
||||
- Some applications may require specific hardware information to function properly
|
||||
|
||||
## Examples
|
||||
|
||||
### Example 1: Set individual SMBIOS settings for a VM
|
||||
|
||||
```powershell
|
||||
$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential)
|
||||
Set-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100 -Manufacturer "Dell Inc." -Product "PowerEdge R740" -Serial "ABC123"
|
||||
```
|
||||
|
||||
This example sets the manufacturer, product, and serial number SMBIOS settings for VM 100 on node pve1.
|
||||
|
||||
### Example 2: Set SMBIOS settings using an object
|
||||
|
||||
```powershell
|
||||
$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential)
|
||||
$smbios = New-Object PSProxmox.Models.ProxmoxVMSMBIOS
|
||||
$smbios.Manufacturer = "Dell Inc."
|
||||
$smbios.Product = "PowerEdge R740"
|
||||
$smbios.Serial = "ABC123"
|
||||
Set-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100 -SMBIOS $smbios
|
||||
```
|
||||
|
||||
This example creates a ProxmoxVMSMBIOS object and uses it to set the SMBIOS settings for VM 100.
|
||||
|
||||
### Example 3: Get current SMBIOS settings, modify them, and update
|
||||
|
||||
```powershell
|
||||
$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential)
|
||||
$smbios = Get-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100
|
||||
$smbios.Manufacturer = "Dell Inc."
|
||||
$smbios.Product = "PowerEdge R740"
|
||||
Set-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100 -SMBIOS $smbios -PassThru
|
||||
```
|
||||
|
||||
This example retrieves the current SMBIOS settings for VM 100, modifies them, and then updates the VM with the new settings.
|
||||
|
||||
## Related Links
|
||||
|
||||
- [Get-ProxmoxVMSMBIOS](Get-ProxmoxVMSMBIOS.md)
|
||||
- [New-ProxmoxVMBuilder](New-ProxmoxVMBuilder.md)
|
||||
- [New-ProxmoxVM](New-ProxmoxVM.md)
|
||||
@@ -0,0 +1,66 @@
|
||||
# SMBIOS-Examples.ps1
|
||||
# This script demonstrates how to use SMBIOS settings with the PSProxmox module.
|
||||
|
||||
# Import the PSProxmox module
|
||||
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"
|
||||
|
||||
# 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"
|
||||
|
||||
# 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"
|
||||
|
||||
# Example 3: Create a VM using the builder pattern with automatic SMBIOS settings
|
||||
$builder = New-ProxmoxVMBuilder -Name "hp-server" -AutomaticSMBIOS -SMBIOSProfile "HP"
|
||||
$builder.WithMemory(4096)
|
||||
.WithCores(2)
|
||||
.WithDisk(50, "local-lvm")
|
||||
.WithNetwork("virtio", "vmbr0")
|
||||
.WithStart($true)
|
||||
$vm3 = New-ProxmoxVM -Connection $connection -Node "pve1" -Builder $builder
|
||||
|
||||
# Example 4: Create a VM using the builder pattern with manual SMBIOS settings
|
||||
$builder = New-ProxmoxVMBuilder -Name "custom-server"
|
||||
$builder.WithMemory(4096)
|
||||
.WithCores(2)
|
||||
.WithDisk(50, "local-lvm")
|
||||
.WithNetwork("virtio", "vmbr0")
|
||||
.WithSMBIOSManufacturer("Custom Manufacturer")
|
||||
.WithSMBIOSProduct("Custom Product")
|
||||
.WithSMBIOSVersion("1.0")
|
||||
.WithSMBIOSSerial("CUSTOM123")
|
||||
.WithStart($true)
|
||||
$vm4 = New-ProxmoxVM -Connection $connection -Node "pve1" -Builder $builder
|
||||
|
||||
# Example 5: Get SMBIOS settings for an existing VM
|
||||
$smbios = Get-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100
|
||||
Write-Host "Current SMBIOS settings for VM 100:"
|
||||
Write-Host "Manufacturer: $($smbios.Manufacturer)"
|
||||
Write-Host "Product: $($smbios.Product)"
|
||||
Write-Host "Version: $($smbios.Version)"
|
||||
Write-Host "Serial: $($smbios.Serial)"
|
||||
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"
|
||||
|
||||
# Example 7: Update SMBIOS settings for an existing VM using a manufacturer profile
|
||||
$smbios = ProxmoxVMSMBIOSProfile.GetProfile("VMware")
|
||||
Set-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 101 -SMBIOS $smbios
|
||||
|
||||
# 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"
|
||||
$builder.WithMemory(8192)
|
||||
.WithCores(4)
|
||||
.WithDisk(100, "local-lvm")
|
||||
.WithNetwork("virtio", "vmbr0")
|
||||
.WithStart($true)
|
||||
$vm5 = New-ProxmoxVM -Connection $connection -Node "pve1" -Builder $builder
|
||||
|
||||
# Disconnect from the server when done
|
||||
Disconnect-ProxmoxServer -Connection $connection
|
||||
@@ -1,7 +1,7 @@
|
||||
@{
|
||||
RootModule = 'PSProxmox.psm1'
|
||||
NestedModules = @('bin\PSProxmox.dll')
|
||||
ModuleVersion = '2025.04.28.2035'
|
||||
ModuleVersion = '2025.05.07.1046'
|
||||
GUID = 'd24f0894-3d0c-4ef1-a41e-b273c3db86ad'
|
||||
Author = 'PSProxmox Team'
|
||||
CompanyName = 'PSProxmox'
|
||||
@@ -98,3 +98,5 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+237
-22
@@ -1,48 +1,263 @@
|
||||
# PSProxmox Module
|
||||
# PSProxmox
|
||||
|
||||
This directory contains the PowerShell module files for PSProxmox.
|
||||
PSProxmox is a C#-based PowerShell module for managing Proxmox VE clusters. It provides a comprehensive set of cmdlets for interacting with Proxmox VE API, featuring structured return objects, mass deployment tools, automatic IP management, and more.
|
||||
|
||||
## Structure
|
||||
## Features
|
||||
|
||||
- **PSProxmox.psd1**: The module manifest file
|
||||
- **bin/**: Contains the compiled DLL
|
||||
- **Session Management**: Authenticate and persist sessions with Proxmox VE clusters
|
||||
- **Core CRUD Operations**: Manage VMs, Storage, Network, Users, Roles, SDN, and Clusters
|
||||
- **Templates**: Create and use VM deployment templates
|
||||
- **Mass Creation**: Bulk create VMs with prefix/counter
|
||||
- **IP Management**: CIDR parsing, subnetting, FIFO IP queue assignment
|
||||
- **Structured Objects**: All outputs are typed C# classes (PowerShell-native)
|
||||
- **Pipeline Support**: Cmdlets support pipeline input where appropriate
|
||||
|
||||
## Building the Module
|
||||
## Project Structure
|
||||
|
||||
The module is built using the build script in the Scripts directory:
|
||||
- **Module/**: Contains the PowerShell module files
|
||||
- **PSProxmox/**: Contains the C# source code for the module
|
||||
- **Documentation/**: Contains detailed documentation and examples
|
||||
- **Scripts/**: Contains build and installation scripts
|
||||
- **Release/**: Contains built releases (created by build script)
|
||||
|
||||
## Installation
|
||||
|
||||
### From PowerShell Gallery (Recommended)
|
||||
|
||||
```powershell
|
||||
.\Scripts\build.ps1
|
||||
# Install from PowerShell Gallery
|
||||
Install-Module -Name PSProxmox -Scope CurrentUser
|
||||
```
|
||||
|
||||
This will compile the C# code from the PSProxmox directory and place the DLL in the bin directory.
|
||||
|
||||
## Installing the Module
|
||||
|
||||
You can install the module using the installation script in the Scripts directory:
|
||||
### Manual Installation
|
||||
|
||||
```powershell
|
||||
# Clone the repository
|
||||
git clone https://github.com/freedbygrace/PSProxmox.git
|
||||
cd PSProxmox
|
||||
|
||||
# Build the module
|
||||
.\Scripts\build.ps1
|
||||
|
||||
# Install the module
|
||||
.\Scripts\Install-PSProxmox.ps1
|
||||
```
|
||||
|
||||
This will copy the module files to your PowerShell modules directory.
|
||||
## Getting Started
|
||||
|
||||
## Manual Installation
|
||||
### Connecting to a Proxmox VE Server
|
||||
|
||||
You can manually install the module by copying the files to your PowerShell modules directory:
|
||||
|
||||
For Windows PowerShell:
|
||||
```powershell
|
||||
Copy-Item -Path .\Module\* -Destination "$env:USERPROFILE\Documents\WindowsPowerShell\Modules\PSProxmox" -Recurse -Force
|
||||
# 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 using a credential object
|
||||
$credential = Get-Credential
|
||||
$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Credential $credential -Realm "pam"
|
||||
```
|
||||
|
||||
For PowerShell Core:
|
||||
### Managing Virtual Machines
|
||||
|
||||
```powershell
|
||||
Copy-Item -Path .\Module\* -Destination "$env:USERPROFILE\Documents\PowerShell\Modules\PSProxmox" -Recurse -Force
|
||||
# Get all VMs
|
||||
$vms = Get-ProxmoxVM -Connection $connection
|
||||
|
||||
# Get a specific VM
|
||||
$vm = Get-ProxmoxVM -Connection $connection -VMID 100
|
||||
|
||||
# Create a new VM
|
||||
$vm = New-ProxmoxVM -Connection $connection -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"
|
||||
$builder.WithMemory(4096)
|
||||
.WithCores(2)
|
||||
.WithDisk(50, "local-lvm")
|
||||
.WithNetwork("virtio", "vmbr0")
|
||||
.WithIPConfig("192.168.1.10/24", "192.168.1.1")
|
||||
.WithStart($true)
|
||||
|
||||
$vm = New-ProxmoxVM -Connection $connection -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
|
||||
|
||||
# Remove a VM
|
||||
Remove-ProxmoxVM -Connection $connection -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"
|
||||
|
||||
# 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
|
||||
|
||||
# Create multiple VMs from a template
|
||||
$vms = New-ProxmoxVMFromTemplate -Connection $connection -Node "pve1" -TemplateName "Ubuntu-Template" -Prefix "web" -Count 3 -Start
|
||||
```
|
||||
|
||||
### Managing Storage
|
||||
|
||||
```powershell
|
||||
# Get all storage
|
||||
$storage = Get-ProxmoxStorage -Connection $connection
|
||||
|
||||
# Get storage on a specific node
|
||||
$storage = Get-ProxmoxStorage -Connection $connection -Node "pve1"
|
||||
|
||||
# Create a new storage
|
||||
$storage = New-ProxmoxStorage -Connection $connection -Name "backup" -Type "dir" -Path "/mnt/backup" -Content "backup,iso"
|
||||
|
||||
# Remove a storage
|
||||
Remove-ProxmoxStorage -Connection $connection -Name "backup" -Confirm:$false
|
||||
```
|
||||
|
||||
### Managing Networks
|
||||
|
||||
```powershell
|
||||
# Get all network interfaces on a node
|
||||
$networks = Get-ProxmoxNetwork -Connection $connection -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
|
||||
|
||||
# Remove a network interface
|
||||
Remove-ProxmoxNetwork -Connection $connection -Node "pve1" -Interface "vmbr1" -Confirm:$false
|
||||
```
|
||||
|
||||
### Managing Users and Roles
|
||||
|
||||
```powershell
|
||||
# Get all users
|
||||
$users = Get-ProxmoxUser -Connection $connection
|
||||
|
||||
# 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"
|
||||
|
||||
# Remove a user
|
||||
Remove-ProxmoxUser -Connection $connection -UserID "john@pam" -Confirm:$false
|
||||
|
||||
# Get all roles
|
||||
$roles = Get-ProxmoxRole -Connection $connection
|
||||
|
||||
# Create a new role
|
||||
$role = New-ProxmoxRole -Connection $connection -RoleID "Developer" -Privileges "VM.Allocate", "VM.Config.Disk", "VM.Config.CPU", "VM.PowerMgmt"
|
||||
|
||||
# Remove a role
|
||||
Remove-ProxmoxRole -Connection $connection -RoleID "Developer" -Confirm:$false
|
||||
```
|
||||
|
||||
### Managing SDN
|
||||
|
||||
```powershell
|
||||
# Get all SDN zones
|
||||
$zones = Get-ProxmoxSDNZone -Connection $connection
|
||||
|
||||
# Create a new SDN zone
|
||||
$zone = New-ProxmoxSDNZone -Connection $connection -Zone "zone1" -Type "vlan" -Bridge "vmbr0"
|
||||
|
||||
# Remove an SDN zone
|
||||
Remove-ProxmoxSDNZone -Connection $connection -Zone "zone1" -Confirm:$false
|
||||
|
||||
# Get all SDN VNets
|
||||
$vnets = Get-ProxmoxSDNVnet -Connection $connection
|
||||
|
||||
# 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"
|
||||
|
||||
# Remove an SDN VNet
|
||||
Remove-ProxmoxSDNVnet -Connection $connection -VNet "vnet1" -Confirm:$false
|
||||
```
|
||||
|
||||
### Managing Clusters
|
||||
|
||||
```powershell
|
||||
# Get cluster information
|
||||
$cluster = Get-ProxmoxCluster -Connection $connection
|
||||
|
||||
# Join a node to a cluster
|
||||
$securePassword = ConvertTo-SecureString "password" -AsPlainText -Force
|
||||
Join-ProxmoxCluster -Connection $connection -ClusterName "cluster1" -HostName "pve1" -Password $securePassword
|
||||
|
||||
# Leave a cluster
|
||||
Leave-ProxmoxCluster -Connection $connection -Force
|
||||
|
||||
# Create a cluster backup
|
||||
$backup = New-ProxmoxClusterBackup -Connection $connection -Compress -Wait
|
||||
|
||||
# Restore a cluster backup
|
||||
Restore-ProxmoxClusterBackup -Connection $connection -BackupID "vzdump-cluster-2023_04_28-12_00_00.vma.lzo" -Force -Wait
|
||||
```
|
||||
|
||||
### Managing IP Addresses
|
||||
|
||||
```powershell
|
||||
# Create a new IP pool
|
||||
$pool = New-ProxmoxIPPool -Name "Production" -CIDR "192.168.1.0/24" -ExcludeIPs "192.168.1.1", "192.168.1.254"
|
||||
|
||||
# Get all IP pools
|
||||
$pools = Get-ProxmoxIPPool
|
||||
|
||||
# Get a specific IP pool
|
||||
$pool = Get-ProxmoxIPPool -Name "Production"
|
||||
|
||||
# Clear an IP pool
|
||||
Clear-ProxmoxIPPool -Name "Production"
|
||||
```
|
||||
|
||||
## Disconnecting
|
||||
|
||||
```powershell
|
||||
# Disconnect from the server
|
||||
Disconnect-ProxmoxServer -Connection $connection
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
### Building the Module
|
||||
|
||||
To build the module from source:
|
||||
|
||||
```powershell
|
||||
# Run the build script
|
||||
.\Scripts\build.ps1
|
||||
```
|
||||
|
||||
This will:
|
||||
1. Compile the C# code
|
||||
2. Create a versioned release in the Release folder
|
||||
3. Update the Module folder with the latest build
|
||||
4. Create a ZIP package for distribution
|
||||
|
||||
### Project Organization
|
||||
|
||||
- **C# Source Code**: All C# source code is in the PSProxmox folder
|
||||
- **PowerShell Module**: The PowerShell module files are in the Module folder
|
||||
- **Documentation**: Comprehensive documentation is in the Documentation folder
|
||||
- **Scripts**: Build and installation scripts are in the Scripts folder
|
||||
|
||||
## Documentation
|
||||
|
||||
For detailed documentation, see the [Documentation](../Documentation) directory.
|
||||
For detailed documentation, see the [Documentation](Documentation) directory. The documentation includes:
|
||||
|
||||
- [Cmdlet Reference](Documentation/cmdlets/README.md)
|
||||
- [Examples](Documentation/examples/README.md)
|
||||
- [Guides](Documentation/guides/README.md)
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are welcome! Please feel free to submit a Pull Request.
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the MIT License - see the LICENSE file for details.
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using PSProxmox.Models;
|
||||
using PSProxmox.Session;
|
||||
|
||||
namespace PSProxmox.Cmdlets
|
||||
{
|
||||
/// <summary>
|
||||
/// <para type="synopsis">Gets the SMBIOS settings for a Proxmox VM.</para>
|
||||
/// <para type="description">The Get-ProxmoxVMSMBIOS cmdlet retrieves the SMBIOS settings for a Proxmox VM.</para>
|
||||
/// <example>
|
||||
/// <para>Get SMBIOS settings for a VM</para>
|
||||
/// <code>Get-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100</code>
|
||||
/// </example>
|
||||
/// </summary>
|
||||
[Cmdlet(VerbsCommon.Get, "ProxmoxVMSMBIOS")]
|
||||
[OutputType(typeof(ProxmoxVMSMBIOS))]
|
||||
public class GetProxmoxVMSMBIOSCmdlet : PSCmdlet
|
||||
{
|
||||
/// <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 node where the VM is located.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = true, Position = 1)]
|
||||
public string Node { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">The ID of the VM.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = true, Position = 2)]
|
||||
public int VMID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">Return the raw JSON response.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false)]
|
||||
public SwitchParameter RawJson { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Processes the cmdlet.
|
||||
/// </summary>
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
try
|
||||
{
|
||||
var client = new ProxmoxApiClient(Connection, this);
|
||||
|
||||
// Get the VM configuration
|
||||
string response = client.Get($"nodes/{Node}/qemu/{VMID}/config");
|
||||
var configData = JsonUtility.DeserializeResponse<JObject>(response);
|
||||
|
||||
if (RawJson.IsPresent)
|
||||
{
|
||||
WriteObject(response);
|
||||
return;
|
||||
}
|
||||
|
||||
// Extract SMBIOS settings
|
||||
var smbios = new ProxmoxVMSMBIOS();
|
||||
if (configData.TryGetValue("data", out JToken dataToken) &&
|
||||
dataToken is JObject data &&
|
||||
data.TryGetValue("smbios", out JToken smbiosToken))
|
||||
{
|
||||
string smbiosString = smbiosToken.ToString();
|
||||
smbios = ProxmoxVMSMBIOS.FromProxmoxString(smbiosString);
|
||||
}
|
||||
|
||||
WriteObject(smbios);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteError(new ErrorRecord(ex, "GetProxmoxVMSMBIOSError", ErrorCategory.OperationStopped, Connection));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,6 +92,55 @@ namespace PSProxmox.Cmdlets
|
||||
[Parameter(Mandatory = false)]
|
||||
public string IPPool { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">The SMBIOS manufacturer information.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false)]
|
||||
public string SMBIOSManufacturer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">The SMBIOS product information.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false)]
|
||||
public string SMBIOSProduct { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">The SMBIOS version information.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false)]
|
||||
public string SMBIOSVersion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">The SMBIOS serial number.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false)]
|
||||
public string SMBIOSSerial { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">The SMBIOS family information.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false)]
|
||||
public string SMBIOSFamily { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">The SMBIOS UUID.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false)]
|
||||
public string SMBIOSUUID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">Whether to automatically generate SMBIOS values.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false)]
|
||||
public SwitchParameter AutomaticSMBIOS { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">The manufacturer profile to use for SMBIOS values. Valid values are: Proxmox, Dell, HP, Lenovo, VMware, HyperV, VirtualBox, Random.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false)]
|
||||
[ValidateSet("Proxmox", "Dell", "HP", "Lenovo", "VMware", "HyperV", "VirtualBox", "Random")]
|
||||
public string SMBIOSProfile { get; set; } = "Random";
|
||||
|
||||
/// <summary>
|
||||
/// Processes the cmdlet.
|
||||
/// </summary>
|
||||
@@ -129,6 +178,47 @@ namespace PSProxmox.Cmdlets
|
||||
builder.WithTags(Tags);
|
||||
}
|
||||
|
||||
// Set SMBIOS settings based on parameters
|
||||
if (AutomaticSMBIOS.IsPresent)
|
||||
{
|
||||
// Use the specified profile or Random if not specified
|
||||
builder.WithSMBIOSProfile(SMBIOSProfile);
|
||||
WriteVerbose($"Using automatic SMBIOS settings with profile: {SMBIOSProfile}");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set individual SMBIOS settings if provided
|
||||
if (!string.IsNullOrEmpty(SMBIOSManufacturer))
|
||||
{
|
||||
builder.WithSMBIOSManufacturer(SMBIOSManufacturer);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(SMBIOSProduct))
|
||||
{
|
||||
builder.WithSMBIOSProduct(SMBIOSProduct);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(SMBIOSVersion))
|
||||
{
|
||||
builder.WithSMBIOSVersion(SMBIOSVersion);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(SMBIOSSerial))
|
||||
{
|
||||
builder.WithSMBIOSSerial(SMBIOSSerial);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(SMBIOSFamily))
|
||||
{
|
||||
builder.WithSMBIOSFamily(SMBIOSFamily);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(SMBIOSUUID))
|
||||
{
|
||||
builder.WithSMBIOSUUID(SMBIOSUUID);
|
||||
}
|
||||
}
|
||||
|
||||
WriteObject(builder);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -112,6 +112,19 @@ namespace PSProxmox.Cmdlets
|
||||
[Parameter(Mandatory = false, ParameterSetName = "Direct")]
|
||||
public string IPPool { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">Whether to automatically generate SMBIOS values.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false, ParameterSetName = "Direct")]
|
||||
public SwitchParameter AutomaticSMBIOS { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">The manufacturer profile to use for SMBIOS values. Valid values are: Proxmox, Dell, HP, Lenovo, VMware, HyperV, VirtualBox, Random.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false, ParameterSetName = "Direct")]
|
||||
[ValidateSet("Proxmox", "Dell", "HP", "Lenovo", "VMware", "HyperV", "VirtualBox", "Random")]
|
||||
public string SMBIOSProfile { get; set; } = "Random";
|
||||
|
||||
/// <summary>
|
||||
/// Processes the cmdlet.
|
||||
/// </summary>
|
||||
@@ -180,6 +193,18 @@ namespace PSProxmox.Cmdlets
|
||||
// Add disk
|
||||
parameters["ide0"] = $"{Storage}:{DiskSize}";
|
||||
|
||||
// Add SMBIOS settings if requested
|
||||
if (AutomaticSMBIOS.IsPresent)
|
||||
{
|
||||
var smbios = ProxmoxVMSMBIOSProfile.GetProfile(SMBIOSProfile);
|
||||
string smbiosString = smbios.ToProxmoxString();
|
||||
if (!string.IsNullOrEmpty(smbiosString))
|
||||
{
|
||||
parameters["smbios"] = smbiosString;
|
||||
WriteVerbose($"Using automatic SMBIOS settings with profile: {SMBIOSProfile}");
|
||||
}
|
||||
}
|
||||
|
||||
vmid = VMID.Value;
|
||||
vmName = Name;
|
||||
ipPool = IPPool;
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Management.Automation;
|
||||
using PSProxmox.Models;
|
||||
using PSProxmox.Session;
|
||||
|
||||
namespace PSProxmox.Cmdlets
|
||||
{
|
||||
/// <summary>
|
||||
/// <para type="synopsis">Sets the SMBIOS settings for a Proxmox VM.</para>
|
||||
/// <para type="description">The Set-ProxmoxVMSMBIOS cmdlet sets the SMBIOS settings for a Proxmox VM.</para>
|
||||
/// <example>
|
||||
/// <para>Set SMBIOS settings for a VM</para>
|
||||
/// <code>Set-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100 -Manufacturer "Dell Inc." -Product "PowerEdge R740" -Serial "ABC123"</code>
|
||||
/// </example>
|
||||
/// <example>
|
||||
/// <para>Set SMBIOS settings using a SMBIOS object</para>
|
||||
/// <code>$smbios = New-Object PSProxmox.Models.ProxmoxVMSMBIOS
|
||||
/// $smbios.Manufacturer = "Dell Inc."
|
||||
/// $smbios.Product = "PowerEdge R740"
|
||||
/// $smbios.Serial = "ABC123"
|
||||
/// Set-ProxmoxVMSMBIOS -Connection $connection -Node "pve1" -VMID 100 -SMBIOS $smbios</code>
|
||||
/// </example>
|
||||
/// </summary>
|
||||
[Cmdlet(VerbsCommon.Set, "ProxmoxVMSMBIOS", SupportsShouldProcess = true)]
|
||||
[OutputType(typeof(ProxmoxVMSMBIOS))]
|
||||
public class SetProxmoxVMSMBIOSCmdlet : PSCmdlet
|
||||
{
|
||||
/// <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 node where the VM is located.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = true, Position = 1)]
|
||||
public string Node { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">The ID of the VM.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = true, Position = 2)]
|
||||
public int VMID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">The SMBIOS settings object.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false, ParameterSetName = "SMBIOSObject")]
|
||||
public ProxmoxVMSMBIOS SMBIOS { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">The manufacturer information.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false, ParameterSetName = "Individual")]
|
||||
public string Manufacturer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">The product information.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false, ParameterSetName = "Individual")]
|
||||
public string Product { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">The version information.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false, ParameterSetName = "Individual")]
|
||||
public string Version { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">The serial number.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false, ParameterSetName = "Individual")]
|
||||
public string Serial { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">The system family.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false, ParameterSetName = "Individual")]
|
||||
public string Family { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">The system UUID.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false, ParameterSetName = "Individual")]
|
||||
public string UUID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para type="description">Return the updated SMBIOS settings.</para>
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = false)]
|
||||
public SwitchParameter PassThru { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Processes the cmdlet.
|
||||
/// </summary>
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
try
|
||||
{
|
||||
var client = new ProxmoxApiClient(Connection, this);
|
||||
|
||||
// Create SMBIOS settings
|
||||
ProxmoxVMSMBIOS smbiosSettings;
|
||||
if (ParameterSetName == "SMBIOSObject")
|
||||
{
|
||||
smbiosSettings = SMBIOS ?? new ProxmoxVMSMBIOS();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get current settings first
|
||||
string response = client.Get($"nodes/{Node}/qemu/{VMID}/config");
|
||||
var configData = JsonUtility.DeserializeResponse<dynamic>(response);
|
||||
|
||||
string currentSmbiosString = configData.data.smbios;
|
||||
smbiosSettings = string.IsNullOrEmpty(currentSmbiosString)
|
||||
? new ProxmoxVMSMBIOS()
|
||||
: ProxmoxVMSMBIOS.FromProxmoxString(currentSmbiosString);
|
||||
|
||||
// Update with provided values
|
||||
if (!string.IsNullOrEmpty(Manufacturer))
|
||||
smbiosSettings.Manufacturer = Manufacturer;
|
||||
|
||||
if (!string.IsNullOrEmpty(Product))
|
||||
smbiosSettings.Product = Product;
|
||||
|
||||
if (!string.IsNullOrEmpty(Version))
|
||||
smbiosSettings.Version = Version;
|
||||
|
||||
if (!string.IsNullOrEmpty(Serial))
|
||||
smbiosSettings.Serial = Serial;
|
||||
|
||||
if (!string.IsNullOrEmpty(Family))
|
||||
smbiosSettings.Family = Family;
|
||||
|
||||
if (!string.IsNullOrEmpty(UUID))
|
||||
smbiosSettings.UUID = UUID;
|
||||
}
|
||||
|
||||
// Convert to Proxmox format
|
||||
string smbiosString = smbiosSettings.ToProxmoxString();
|
||||
|
||||
if (string.IsNullOrEmpty(smbiosString))
|
||||
{
|
||||
WriteWarning("No SMBIOS settings specified. No changes will be made.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Confirm the operation
|
||||
if (!ShouldProcess($"VM {VMID} on node {Node}", $"Set SMBIOS settings to {smbiosString}"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the VM configuration
|
||||
var parameters = new Dictionary<string, string>
|
||||
{
|
||||
["smbios"] = smbiosString
|
||||
};
|
||||
|
||||
client.Put($"nodes/{Node}/qemu/{VMID}/config", parameters);
|
||||
WriteVerbose($"SMBIOS settings updated for VM {VMID} on node {Node}");
|
||||
|
||||
// Return the updated settings if requested
|
||||
if (PassThru.IsPresent)
|
||||
{
|
||||
WriteObject(smbiosSettings);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteError(new ErrorRecord(ex, "SetProxmoxVMSMBIOSError", ErrorCategory.OperationStopped, Connection));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,6 +71,11 @@ namespace PSProxmox.Models
|
||||
/// </summary>
|
||||
public string IPPool { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the SMBIOS settings for the VM.
|
||||
/// </summary>
|
||||
public ProxmoxVMSMBIOS SMBIOS { get; set; } = new ProxmoxVMSMBIOS();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ProxmoxVMBuilder"/> class.
|
||||
/// </summary>
|
||||
@@ -341,6 +346,94 @@ namespace PSProxmox.Models
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the SMBIOS manufacturer for the VM.
|
||||
/// </summary>
|
||||
/// <param name="manufacturer">The manufacturer name.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ProxmoxVMBuilder WithSMBIOSManufacturer(string manufacturer)
|
||||
{
|
||||
SMBIOS.Manufacturer = manufacturer;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the SMBIOS product name for the VM.
|
||||
/// </summary>
|
||||
/// <param name="product">The product name.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ProxmoxVMBuilder WithSMBIOSProduct(string product)
|
||||
{
|
||||
SMBIOS.Product = product;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the SMBIOS version for the VM.
|
||||
/// </summary>
|
||||
/// <param name="version">The version.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ProxmoxVMBuilder WithSMBIOSVersion(string version)
|
||||
{
|
||||
SMBIOS.Version = version;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the SMBIOS serial number for the VM.
|
||||
/// </summary>
|
||||
/// <param name="serial">The serial number.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ProxmoxVMBuilder WithSMBIOSSerial(string serial)
|
||||
{
|
||||
SMBIOS.Serial = serial;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the SMBIOS family for the VM.
|
||||
/// </summary>
|
||||
/// <param name="family">The family.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ProxmoxVMBuilder WithSMBIOSFamily(string family)
|
||||
{
|
||||
SMBIOS.Family = family;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the SMBIOS UUID for the VM.
|
||||
/// </summary>
|
||||
/// <param name="uuid">The UUID.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ProxmoxVMBuilder WithSMBIOSUUID(string uuid)
|
||||
{
|
||||
SMBIOS.UUID = uuid;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets all SMBIOS settings for the VM at once.
|
||||
/// </summary>
|
||||
/// <param name="smbios">The SMBIOS settings.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ProxmoxVMBuilder WithSMBIOS(ProxmoxVMSMBIOS smbios)
|
||||
{
|
||||
SMBIOS = smbios ?? new ProxmoxVMSMBIOS();
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets SMBIOS settings based on a manufacturer profile.
|
||||
/// </summary>
|
||||
/// <param name="manufacturer">The manufacturer profile to use.</param>
|
||||
/// <returns>The builder instance.</returns>
|
||||
public ProxmoxVMBuilder WithSMBIOSProfile(string manufacturer)
|
||||
{
|
||||
SMBIOS = ProxmoxVMSMBIOSProfile.GetProfile(manufacturer);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the VM configuration parameters.
|
||||
/// </summary>
|
||||
@@ -366,6 +459,13 @@ namespace PSProxmox.Models
|
||||
parameters["tags"] = Tags;
|
||||
}
|
||||
|
||||
// Add SMBIOS settings if any are specified
|
||||
string smbiosString = SMBIOS.ToProxmoxString();
|
||||
if (!string.IsNullOrEmpty(smbiosString))
|
||||
{
|
||||
parameters["smbios"] = smbiosString;
|
||||
}
|
||||
|
||||
// Add network interfaces
|
||||
for (int i = 0; i < _networkInterfaces.Count; i++)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace PSProxmox.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents SMBIOS settings for a Proxmox VM.
|
||||
/// </summary>
|
||||
public class ProxmoxVMSMBIOS
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the manufacturer information.
|
||||
/// </summary>
|
||||
[JsonProperty("manufacturer")]
|
||||
public string Manufacturer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the product information.
|
||||
/// </summary>
|
||||
[JsonProperty("product")]
|
||||
public string Product { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the version information.
|
||||
/// </summary>
|
||||
[JsonProperty("version")]
|
||||
public string Version { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the serial number.
|
||||
/// </summary>
|
||||
[JsonProperty("serial")]
|
||||
public string Serial { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the system family.
|
||||
/// </summary>
|
||||
[JsonProperty("family")]
|
||||
public string Family { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the system UUID.
|
||||
/// </summary>
|
||||
[JsonProperty("uuid")]
|
||||
public string UUID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Converts the SMBIOS settings to a Proxmox API compatible string.
|
||||
/// </summary>
|
||||
/// <returns>A string representation of the SMBIOS settings.</returns>
|
||||
public string ToProxmoxString()
|
||||
{
|
||||
var parts = new System.Collections.Generic.List<string>();
|
||||
|
||||
if (!string.IsNullOrEmpty(Manufacturer))
|
||||
parts.Add($"manufacturer={Manufacturer}");
|
||||
|
||||
if (!string.IsNullOrEmpty(Product))
|
||||
parts.Add($"product={Product}");
|
||||
|
||||
if (!string.IsNullOrEmpty(Version))
|
||||
parts.Add($"version={Version}");
|
||||
|
||||
if (!string.IsNullOrEmpty(Serial))
|
||||
parts.Add($"serial={Serial}");
|
||||
|
||||
if (!string.IsNullOrEmpty(Family))
|
||||
parts.Add($"family={Family}");
|
||||
|
||||
if (!string.IsNullOrEmpty(UUID))
|
||||
parts.Add($"uuid={UUID}");
|
||||
|
||||
return string.Join(",", parts);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a Proxmox API SMBIOS string into a ProxmoxVMSMBIOS object.
|
||||
/// </summary>
|
||||
/// <param name="smbiosString">The SMBIOS string from the Proxmox API.</param>
|
||||
/// <returns>A ProxmoxVMSMBIOS object.</returns>
|
||||
public static ProxmoxVMSMBIOS FromProxmoxString(string smbiosString)
|
||||
{
|
||||
if (string.IsNullOrEmpty(smbiosString))
|
||||
return new ProxmoxVMSMBIOS();
|
||||
|
||||
var result = new ProxmoxVMSMBIOS();
|
||||
var parts = smbiosString.Split(',');
|
||||
|
||||
foreach (var part in parts)
|
||||
{
|
||||
var keyValue = part.Split('=');
|
||||
if (keyValue.Length != 2)
|
||||
continue;
|
||||
|
||||
var key = keyValue[0].Trim();
|
||||
var value = keyValue[1].Trim();
|
||||
|
||||
switch (key.ToLowerInvariant())
|
||||
{
|
||||
case "manufacturer":
|
||||
result.Manufacturer = value;
|
||||
break;
|
||||
case "product":
|
||||
result.Product = value;
|
||||
break;
|
||||
case "version":
|
||||
result.Version = value;
|
||||
break;
|
||||
case "serial":
|
||||
result.Serial = value;
|
||||
break;
|
||||
case "family":
|
||||
result.Family = value;
|
||||
break;
|
||||
case "uuid":
|
||||
result.UUID = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace PSProxmox.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a manufacturer profile for SMBIOS settings.
|
||||
/// </summary>
|
||||
public class ProxmoxVMSMBIOSProfile
|
||||
{
|
||||
private static readonly Random _random = new Random();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the available manufacturer profiles.
|
||||
/// </summary>
|
||||
public static readonly string[] AvailableProfiles = new string[]
|
||||
{
|
||||
"Proxmox",
|
||||
"Dell",
|
||||
"HP",
|
||||
"Lenovo",
|
||||
"VMware",
|
||||
"HyperV",
|
||||
"VirtualBox",
|
||||
"Random"
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a SMBIOS profile for the specified manufacturer.
|
||||
/// </summary>
|
||||
/// <param name="manufacturer">The manufacturer profile to use.</param>
|
||||
/// <returns>A ProxmoxVMSMBIOS object with the manufacturer profile settings.</returns>
|
||||
public static ProxmoxVMSMBIOS GetProfile(string manufacturer)
|
||||
{
|
||||
if (string.IsNullOrEmpty(manufacturer) || manufacturer.Equals("Random", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// Choose a random manufacturer (excluding "Random")
|
||||
var profiles = AvailableProfiles.Where(p => !p.Equals("Random", StringComparison.OrdinalIgnoreCase)).ToArray();
|
||||
manufacturer = profiles[_random.Next(profiles.Length)];
|
||||
}
|
||||
|
||||
switch (manufacturer.ToLowerInvariant())
|
||||
{
|
||||
case "proxmox":
|
||||
return GetProxmoxProfile();
|
||||
case "dell":
|
||||
return GetDellProfile();
|
||||
case "hp":
|
||||
return GetHPProfile();
|
||||
case "lenovo":
|
||||
return GetLenovoProfile();
|
||||
case "vmware":
|
||||
return GetVMwareProfile();
|
||||
case "hyperv":
|
||||
return GetHyperVProfile();
|
||||
case "virtualbox":
|
||||
return GetVirtualBoxProfile();
|
||||
default:
|
||||
throw new ArgumentException($"Unknown manufacturer profile: {manufacturer}");
|
||||
}
|
||||
}
|
||||
|
||||
private static ProxmoxVMSMBIOS GetProxmoxProfile()
|
||||
{
|
||||
return new ProxmoxVMSMBIOS
|
||||
{
|
||||
Manufacturer = "Proxmox",
|
||||
Product = $"Virtual Environment {_random.Next(1, 8)}.{_random.Next(0, 10)}",
|
||||
Version = $"{_random.Next(1, 10)}.{_random.Next(0, 10)}",
|
||||
Serial = GenerateRandomSerial(10),
|
||||
UUID = GenerateRandomUUID(),
|
||||
Family = "Virtual Machine"
|
||||
};
|
||||
}
|
||||
|
||||
private static ProxmoxVMSMBIOS GetDellProfile()
|
||||
{
|
||||
var models = new string[]
|
||||
{
|
||||
"PowerEdge R640",
|
||||
"PowerEdge R740",
|
||||
"PowerEdge R750",
|
||||
"PowerEdge R840",
|
||||
"PowerEdge R940",
|
||||
"PowerEdge T640"
|
||||
};
|
||||
|
||||
return new ProxmoxVMSMBIOS
|
||||
{
|
||||
Manufacturer = "Dell Inc.",
|
||||
Product = models[_random.Next(models.Length)],
|
||||
Version = $"{_random.Next(1, 5)}.{_random.Next(0, 10)}",
|
||||
Serial = $"{GenerateRandomString(5, true)}{_random.Next(10000, 99999)}",
|
||||
UUID = GenerateRandomUUID(),
|
||||
Family = "PowerEdge"
|
||||
};
|
||||
}
|
||||
|
||||
private static ProxmoxVMSMBIOS GetHPProfile()
|
||||
{
|
||||
var models = new string[]
|
||||
{
|
||||
"ProLiant DL360 Gen10",
|
||||
"ProLiant DL380 Gen10",
|
||||
"ProLiant DL560 Gen10",
|
||||
"ProLiant ML350 Gen10",
|
||||
"ProLiant BL460c Gen10"
|
||||
};
|
||||
|
||||
return new ProxmoxVMSMBIOS
|
||||
{
|
||||
Manufacturer = "HP",
|
||||
Product = models[_random.Next(models.Length)],
|
||||
Version = $"U{_random.Next(10, 50)}",
|
||||
Serial = $"USE{_random.Next(100000, 999999)}",
|
||||
UUID = GenerateRandomUUID(),
|
||||
Family = "ProLiant"
|
||||
};
|
||||
}
|
||||
|
||||
private static ProxmoxVMSMBIOS GetLenovoProfile()
|
||||
{
|
||||
var models = new string[]
|
||||
{
|
||||
"ThinkSystem SR650",
|
||||
"ThinkSystem SR630",
|
||||
"ThinkSystem SR850",
|
||||
"ThinkSystem SR950",
|
||||
"ThinkSystem ST550"
|
||||
};
|
||||
|
||||
return new ProxmoxVMSMBIOS
|
||||
{
|
||||
Manufacturer = "Lenovo",
|
||||
Product = models[_random.Next(models.Length)],
|
||||
Version = $"ThinkSystem {_random.Next(1, 5)}",
|
||||
Serial = $"{GenerateRandomString(4, true)}{GenerateRandomString(6, false)}",
|
||||
UUID = GenerateRandomUUID(),
|
||||
Family = "ThinkSystem"
|
||||
};
|
||||
}
|
||||
|
||||
private static ProxmoxVMSMBIOS GetVMwareProfile()
|
||||
{
|
||||
return new ProxmoxVMSMBIOS
|
||||
{
|
||||
Manufacturer = "VMware, Inc.",
|
||||
Product = $"VMware Virtual Platform {_random.Next(1, 8)}",
|
||||
Version = $"VMware-{_random.Next(1, 10)}.{_random.Next(0, 10)}",
|
||||
Serial = GenerateRandomSerial(10),
|
||||
UUID = GenerateRandomUUID(),
|
||||
Family = "Virtual Machine"
|
||||
};
|
||||
}
|
||||
|
||||
private static ProxmoxVMSMBIOS GetHyperVProfile()
|
||||
{
|
||||
return new ProxmoxVMSMBIOS
|
||||
{
|
||||
Manufacturer = "Microsoft Corporation",
|
||||
Product = $"Hyper-V {_random.Next(2012, 2023)}",
|
||||
Version = $"{_random.Next(1, 10)}.{_random.Next(0, 10)}",
|
||||
Serial = $"MS-{GenerateRandomString(8, false)}",
|
||||
UUID = GenerateRandomUUID(),
|
||||
Family = "Virtual Machine"
|
||||
};
|
||||
}
|
||||
|
||||
private static ProxmoxVMSMBIOS GetVirtualBoxProfile()
|
||||
{
|
||||
return new ProxmoxVMSMBIOS
|
||||
{
|
||||
Manufacturer = "Oracle Corporation",
|
||||
Product = $"VirtualBox {_random.Next(5, 8)}.{_random.Next(0, 10)}",
|
||||
Version = $"{_random.Next(1, 10)}.{_random.Next(0, 10)}",
|
||||
Serial = $"VB-{GenerateRandomString(8, false)}",
|
||||
UUID = GenerateRandomUUID(),
|
||||
Family = "Virtual Machine"
|
||||
};
|
||||
}
|
||||
|
||||
private static string GenerateRandomSerial(int length)
|
||||
{
|
||||
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
return new string(Enumerable.Repeat(chars, length)
|
||||
.Select(s => s[_random.Next(s.Length)]).ToArray());
|
||||
}
|
||||
|
||||
private static string GenerateRandomString(int length, bool uppercase)
|
||||
{
|
||||
const string upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
const string lowerChars = "abcdefghijklmnopqrstuvwxyz";
|
||||
const string digits = "0123456789";
|
||||
|
||||
string chars = uppercase ? upperChars : lowerChars + digits;
|
||||
|
||||
return new string(Enumerable.Repeat(chars, length)
|
||||
.Select(s => s[_random.Next(s.Length)]).ToArray());
|
||||
}
|
||||
|
||||
private static string GenerateRandomUUID()
|
||||
{
|
||||
return Guid.NewGuid().ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user