Add regex and wildcard filtering to Get-* cmdlets

This commit is contained in:
Alphaeus Mote
2025-05-09 14:58:31 -04:00
parent 060ab64d70
commit 9dba7a3bd6
9 changed files with 589 additions and 21 deletions
+108
View File
@@ -0,0 +1,108 @@
# Get-ProxmoxIPPool
Gets IP address pools.
## Syntax
```powershell
Get-ProxmoxIPPool
[-Name <String>]
[-UseRegex]
[<CommonParameters>]
```
## Description
The `Get-ProxmoxIPPool` cmdlet retrieves IP address pools used with Proxmox VE virtual machines. You can retrieve all pools or a specific pool by name.
## Parameters
### -Name
The name of the IP pool to retrieve. Supports wildcards and regex when used with -UseRegex.
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: True
```
### -UseRegex
Use regular expressions for filtering.
```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.ProxmoxIPPool
## Notes
- This cmdlet does not require a connection to a Proxmox VE server as IP pools are stored locally.
- If the `-Name` parameter is specified and the pool is not found, an error will be thrown.
- The `-Name` parameter supports wildcards (e.g., "Production*") by default.
- Use the `-UseRegex` parameter with `-Name` to filter using regular expressions (e.g., "^Prod[a-z]+$").
## Examples
### Example 1: Get all IP pools
```powershell
$pools = Get-ProxmoxIPPool
```
This example gets all IP pools.
### Example 2: Get a specific IP pool by name
```powershell
$pool = Get-ProxmoxIPPool -Name "Production"
```
This example gets the IP pool named "Production".
### Example 3: Get IP pools by name using wildcards
```powershell
$pools = Get-ProxmoxIPPool -Name "Prod*"
```
This example gets all IP pools with names starting with "Prod".
### Example 4: Get IP pools by name using regex
```powershell
$pools = Get-ProxmoxIPPool -Name "^Prod[a-z]+$" -UseRegex
```
This example gets all IP pools with names matching the pattern "Prod" followed by one or more lowercase letters.
## Related Links
- [New-ProxmoxIPPool](New-ProxmoxIPPool.md)
- [Clear-ProxmoxIPPool](Clear-ProxmoxIPPool.md)
+159
View File
@@ -0,0 +1,159 @@
# Get-ProxmoxNode
Gets nodes from a Proxmox VE cluster.
## Syntax
```powershell
Get-ProxmoxNode
[-Connection <ProxmoxConnection>]
[-Name <String>]
[-UseRegex]
[-RawJson]
[<CommonParameters>]
```
## Description
The `Get-ProxmoxNode` cmdlet retrieves nodes from a Proxmox VE cluster. You can retrieve all nodes or a specific node by name.
## Parameters
### -Connection
The connection to the Proxmox VE server.
```yaml
Type: ProxmoxConnection
Parameter Sets: (All)
Aliases:
Required: False
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Name
The name of the node to retrieve. Supports wildcards and regex when used with -UseRegex.
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: True
```
### -UseRegex
Use regular expressions for filtering.
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
```
### -RawJson
Whether to return the raw JSON response instead of parsed objects.
```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.ProxmoxNode
### System.String
## Notes
- This cmdlet requires a connection to a Proxmox VE server. Use `Connect-ProxmoxServer` to establish a connection.
- If no connection is specified, the cmdlet will use the default connection.
- If the `-RawJson` parameter is specified, the raw JSON response will be returned instead of parsed objects.
- If the `-Name` parameter is specified and the node is not found, an error will be thrown.
- The `-Name` parameter supports wildcards (e.g., "pve*") by default.
- Use the `-UseRegex` parameter with `-Name` to filter using regular expressions (e.g., "^pve[0-9]+$").
## Examples
### Example 1: Get all nodes
```powershell
Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential)
$nodes = Get-ProxmoxNode
```
This example gets all nodes from the Proxmox VE cluster.
### Example 2: Get a specific node by name
```powershell
Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential)
$node = Get-ProxmoxNode -Name "pve1"
```
This example gets the node named "pve1".
### Example 3: Get nodes by name using wildcards
```powershell
Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential)
$nodes = Get-ProxmoxNode -Name "pve*"
```
This example gets all nodes with names starting with "pve".
### Example 4: Get nodes by name using regex
```powershell
Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential)
$nodes = Get-ProxmoxNode -Name "^pve[0-9]+$" -UseRegex
```
This example gets all nodes with names matching the pattern "pve" followed by one or more digits.
### Example 5: Get the raw JSON response
```powershell
Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential)
$json = Get-ProxmoxNode -RawJson
```
This example gets the raw JSON response for all nodes.
## Related Links
- [Connect-ProxmoxServer](Connect-ProxmoxServer.md)
- [Get-ProxmoxVM](Get-ProxmoxVM.md)
+66 -11
View File
@@ -6,9 +6,11 @@ Gets virtual machines from Proxmox VE.
```powershell
Get-ProxmoxVM
-Connection <ProxmoxConnection>
[-Connection <ProxmoxConnection>]
[-Node <String>]
[-VMID <Int32>]
[-Name <String>]
[-UseRegex]
[-RawJson]
[<CommonParameters>]
```
@@ -28,7 +30,7 @@ Type: ProxmoxConnection
Parameter Sets: (All)
Aliases:
Required: True
Required: False
Position: 0
Default value: None
Accept pipeline input: False
@@ -67,6 +69,38 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -Name
The name of the virtual machine to retrieve. Supports wildcards and regex when used with -UseRegex.
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: True
```
### -UseRegex
Use regular expressions for filtering.
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
```
### -RawJson
Whether to return the raw JSON response instead of parsed objects.
@@ -100,16 +134,19 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
## Notes
- This cmdlet requires a connection to a Proxmox VE server. Use `Connect-ProxmoxServer` to establish a connection.
- If no connection is specified, the cmdlet will use the default connection.
- If the `-RawJson` parameter is specified, the raw JSON response will be returned instead of parsed objects.
- If the `-VMID` parameter is specified and the VM is not found, an error will be thrown.
- The `-Name` parameter supports wildcards (e.g., "web*") by default.
- Use the `-UseRegex` parameter with `-Name` to filter using regular expressions (e.g., "^web[0-9]+$").
## Examples
### Example 1: Get all VMs
```powershell
$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential)
$vms = Get-ProxmoxVM -Connection $connection
Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential)
$vms = Get-ProxmoxVM
```
This example gets all VMs from all nodes.
@@ -117,8 +154,8 @@ This example gets all VMs from all nodes.
### Example 2: Get VMs on a specific node
```powershell
$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential)
$vms = Get-ProxmoxVM -Connection $connection -Node "pve1"
Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential)
$vms = Get-ProxmoxVM -Node "pve1"
```
This example gets all VMs on the node "pve1".
@@ -126,17 +163,35 @@ This example gets all VMs on the node "pve1".
### Example 3: Get a specific VM by ID
```powershell
$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential)
$vm = Get-ProxmoxVM -Connection $connection -VMID 100
Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential)
$vm = Get-ProxmoxVM -VMID 100
```
This example gets the VM with ID 100.
### Example 4: Get the raw JSON response
### Example 4: Get VMs by name using wildcards
```powershell
$connection = Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential)
$json = Get-ProxmoxVM -Connection $connection -RawJson
Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential)
$vms = Get-ProxmoxVM -Name "web*"
```
This example gets all VMs with names starting with "web".
### Example 5: Get VMs by name using regex
```powershell
Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential)
$vms = Get-ProxmoxVM -Name "^web[0-9]+$" -UseRegex
```
This example gets all VMs with names matching the pattern "web" followed by one or more digits.
### Example 6: Get the raw JSON response
```powershell
Connect-ProxmoxServer -Server "proxmox.example.com" -Credential (Get-Credential)
$json = Get-ProxmoxVM -RawJson
```
This example gets the raw JSON response for all VMs.
@@ -0,0 +1,109 @@
# Get-ProxmoxVMTemplate
Gets virtual machine templates.
## Syntax
```powershell
Get-ProxmoxVMTemplate
[-Name <String>]
[-UseRegex]
[<CommonParameters>]
```
## Description
The `Get-ProxmoxVMTemplate` cmdlet retrieves virtual machine templates. You can retrieve all templates or a specific template by name.
## Parameters
### -Name
The name of the template to retrieve. Supports wildcards and regex when used with -UseRegex.
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: True
```
### -UseRegex
Use regular expressions for filtering.
```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.ProxmoxVMTemplate
## Notes
- This cmdlet does not require a connection to a Proxmox VE server as templates are stored locally.
- If the `-Name` parameter is specified and the template is not found, an error will be thrown.
- The `-Name` parameter supports wildcards (e.g., "Ubuntu*") by default.
- Use the `-UseRegex` parameter with `-Name` to filter using regular expressions (e.g., "^Ubuntu-[0-9]+\\.[0-9]+$").
## Examples
### Example 1: Get all templates
```powershell
$templates = Get-ProxmoxVMTemplate
```
This example gets all templates.
### Example 2: Get a specific template by name
```powershell
$template = Get-ProxmoxVMTemplate -Name "Ubuntu-Template"
```
This example gets the template named "Ubuntu-Template".
### Example 3: Get templates by name using wildcards
```powershell
$templates = Get-ProxmoxVMTemplate -Name "Ubuntu*"
```
This example gets all templates with names starting with "Ubuntu".
### Example 4: Get templates by name using regex
```powershell
$templates = Get-ProxmoxVMTemplate -Name "^Ubuntu-[0-9]+\\.[0-9]+$" -UseRegex
```
This example gets all templates with names matching the pattern "Ubuntu-" followed by a version number (e.g., "Ubuntu-20.04").
## Related Links
- [New-ProxmoxVMTemplate](New-ProxmoxVMTemplate.md)
- [Remove-ProxmoxVMTemplate](Remove-ProxmoxVMTemplate.md)
- [New-ProxmoxVMFromTemplate](New-ProxmoxVMFromTemplate.md)