Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 76 additions & 19 deletions PowerAzPlus-help.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para></maml:para>
<maml:para>@{Text=}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
Expand Down Expand Up @@ -81,7 +81,7 @@
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para></maml:para>
<maml:para>@{Text=}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
Expand Down Expand Up @@ -125,7 +125,7 @@
</dev:remarks>
</command:example>
<command:example>
<maml:title>-------------------------- EXAMPLE 2 --------------------------</maml:title>
<maml:title>-------------------------- Example 2 --------------------------</maml:title>
<dev:code>PS C:\&gt; Export-AllKeyVaultSecrets -VaultName "MyKeyVault" -OutputPath "C:\Backup\Secrets"</dev:code>
<dev:remarks>
<maml:para>Exports all secrets from "MyKeyVault" and saves them in the specified directory.</maml:para>
Expand Down Expand Up @@ -332,7 +332,7 @@
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para></maml:para>
<maml:para>@{Text=}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
Expand All @@ -344,6 +344,18 @@
</command:syntaxItem>
<command:syntaxItem>
<maml:name>Get-VnetAddressSpace</maml:name>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>SubscriptionId</maml:name>
<maml:description>
<maml:para>Specifies one or more Azure subscriptions by Subscription ID to retrieve VNets from. If omitted, the default subscription is used.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String[]</command:parameterValue>
<dev:type>
<maml:name>String[]</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>SortByIp</maml:name>
<maml:description>
Expand All @@ -355,10 +367,25 @@
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para>@{Text=}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
<maml:name>ActionPreference</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:syntaxItem>
<command:syntaxItem>
<maml:name>Get-VnetAddressSpace</maml:name>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Subscription</maml:name>
<maml:name>SubscriptionName</maml:name>
<maml:description>
<maml:para>Specifies one or more Azure subscriptions by Subscription ID to retrieve VNets from. If omitted, the default subscription is used.</maml:para>
<maml:para>Specifies one or more Azure subscriptions by Subscription Name to retrieve VNets from. If omitted, the default subscription is used.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String[]</command:parameterValue>
<dev:type>
Expand All @@ -367,10 +394,21 @@
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>SortByIp</maml:name>
<maml:description>
<maml:para>Sorts the output based on the numerical value of the first IP address in each address prefix.</maml:para>
</maml:description>
<dev:type>
<maml:name>SwitchParameter</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para></maml:para>
<maml:para>@{Text=}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
Expand All @@ -395,21 +433,21 @@
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>SortByIp</maml:name>
<maml:name>SubscriptionId</maml:name>
<maml:description>
<maml:para>Sorts the output based on the numerical value of the first IP address in each address prefix.</maml:para>
<maml:para>Specifies one or more Azure subscriptions by Subscription ID to retrieve VNets from. If omitted, the default subscription is used.</maml:para>
</maml:description>
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
<command:parameterValue required="true" variableLength="false">String[]</command:parameterValue>
<dev:type>
<maml:name>SwitchParameter</maml:name>
<maml:name>String[]</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>Subscription</maml:name>
<maml:name>SubscriptionName</maml:name>
<maml:description>
<maml:para>Specifies one or more Azure subscriptions by Subscription ID to retrieve VNets from. If omitted, the default subscription is used.</maml:para>
<maml:para>Specifies one or more Azure subscriptions by Subscription Name to retrieve VNets from. If omitted, the default subscription is used.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">String[]</command:parameterValue>
<dev:type>
Expand All @@ -418,10 +456,22 @@
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
<maml:name>SortByIp</maml:name>
<maml:description>
<maml:para>Sorts the output based on the numerical value of the first IP address in each address prefix.</maml:para>
</maml:description>
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
<dev:type>
<maml:name>SwitchParameter</maml:name>
<maml:uri />
</dev:type>
<dev:defaultValue>False</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para></maml:para>
<maml:para>@{Text=}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
Expand Down Expand Up @@ -459,14 +509,21 @@
<command:examples>
<command:example>
<maml:title>-------------------------- Example 1 --------------------------</maml:title>
<dev:code>PS C:\&gt; Get-VnetAddressSpace</dev:code>
<dev:remarks>
<maml:para>Retrieves the address space of all VNets in the current signed in tenant and subscription.</maml:para>
</dev:remarks>
</command:example>
<command:example>
<maml:title>-------------------------- Example 2 --------------------------</maml:title>
<dev:code>PS C:\&gt; Get-VnetAddressSpace -AllSubscriptions</dev:code>
<dev:remarks>
<maml:para>Retrieves the address space of all VNets across all enabled Azure subscriptions.</maml:para>
</dev:remarks>
</command:example>
<command:example>
<maml:title>-------------------------- Example 2 --------------------------</maml:title>
<dev:code>PS C:\&gt; Get-VnetAddressSpace -Subscription "12345678-90ab-cdef-1234-567890abcdef","abcdef12-3456-7890-abcd-ef1234567890" -SortByIp</dev:code>
<maml:title>-------------------------- Example 3 --------------------------</maml:title>
<dev:code>PS C:\&gt; Get-VnetAddressSpace -SubscriptionId "12345678-90ab-cdef-1234-567890abcdef","abcdef12-3456-7890-abcd-ef1234567890" -SortByIp</dev:code>
<dev:remarks>
<maml:para>Retrieves the address space of all VNets in the specified subscriptions and sorts the output by IP address.</maml:para>
</dev:remarks>
Expand Down Expand Up @@ -516,7 +573,7 @@
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para></maml:para>
<maml:para>@{Text=}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
Expand Down Expand Up @@ -555,7 +612,7 @@
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="proga">
<maml:name>ProgressAction</maml:name>
<maml:description>
<maml:para></maml:para>
<maml:para>@{Text=}</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">ActionPreference</command:parameterValue>
<dev:type>
Expand Down
2 changes: 1 addition & 1 deletion PowerAzPlus.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'PowerAzPlus.psm1'

# Version number of this module.
ModuleVersion = '1.2.0'
ModuleVersion = '1.2.1'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
22 changes: 16 additions & 6 deletions PowerAzPlus.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -97,33 +97,43 @@ function Import-LogicAppDefinition {

function Get-VnetAddressSpace {
[CmdletBinding(
DefaultParameterSetName = "Subscription"
DefaultParameterSetName = "SubscriptionId"
)]

param(
[Parameter(ParameterSetName = "AllSubscriptions")]
[switch]
$AllSubscriptions,

[Parameter(ParameterSetName = "Subscription")]
[Parameter(ParameterSetName = "SubscriptionId")]
[string[]]
$Subscription,
$SubscriptionId,

[Parameter(ParameterSetName = "SubscriptionName")]
[string[]]
$SubscriptionName,

[Parameter()]
[switch]
$SortByIp
)

# Get subscriptions based on parameter set
$allSubs = if ($AllSubscriptions) {
$allSubs = if ($PSCmdlet.ParameterSetName -eq "AllSubscriptions") {
Get-AzSubscription -WarningAction SilentlyContinue | Where-Object State -EQ 'Enabled'
}
elseif ($PSCmdlet.ParameterSetName -eq "SubscriptionId") {
$SubscriptionId | ForEach-Object { Get-AzSubscription -SubscriptionId $_ -WarningAction SilentlyContinue }
}
elseif ($PSCmdlet.ParameterSetName -eq "SubscriptionName") {
$SubscriptionName | ForEach-Object { Get-AzSubscription -SubscriptionName $_ -WarningAction SilentlyContinue }
}
else {
$Subscription | ForEach-Object { Get-AzSubscription -SubscriptionId $_ -WarningAction SilentlyContinue }
(Get-AzContext).Subscription.Id
}

foreach ($sub in $allSubs) {
Set-AzContext -SubscriptionObject $sub | Out-Null
Set-AzContext -SubscriptionObject $sub -WarningAction SilentlyContinue | Out-Null

$allVnets = Get-AzVirtualNetwork
$results = [System.Collections.Generic.List[PSCustomObject]]::new()
Expand Down
20 changes: 12 additions & 8 deletions docs/Export-AllKeyVaultSecrets.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@ Export-AllKeyVaultSecrets [-VaultName] <String> [[-OutputPath] <String>] [-Progr
```

## DESCRIPTION
The Export-AllKeyVaultSecrets function retrieves all secrets from the specified Azure Key Vault and exports them as backup files. The function ensures the Key Vault exists before proceeding and generates timestamped filenames for each exported secret.
The Export-AllKeyVaultSecrets function retrieves all secrets from the specified Azure Key Vault and exports them as backup files.
The function ensures the Key Vault exists before proceeding and generates timestamped filenames for each exported secret.

## EXAMPLES

### Example 1
```powershell
```
PS C:\> Export-AllKeyVaultSecrets -VaultName "MyKeyVault"
```

Exports all secrets from "MyKeyVault" and saves them in the current working directory.

### Example 2
```powersell
```
PS C:\> Export-AllKeyVaultSecrets -VaultName "MyKeyVault" -OutputPath "C:\Backup\Secrets"
```

Expand All @@ -39,7 +40,9 @@ Exports all secrets from "MyKeyVault" and saves them in the specified directory.
## PARAMETERS

### -OutputPath
Specifies the directory where the exported secrets will be saved. If not provided, the function uses the current working directory. The provided path must exist.
Specifies the directory where the exported secrets will be saved.
If not provided, the function uses the current working directory.
The provided path must exist.

```yaml
Type: String
Expand All @@ -54,7 +57,8 @@ Accept wildcard characters: False
```

### -VaultName
Specifies the name of the Azure Key Vault from which secrets will be exported. This parameter is required.
Specifies the name of the Azure Key Vault from which secrets will be exported.
This parameter is required.

```yaml
Type: String
Expand All @@ -69,6 +73,7 @@ Accept wildcard characters: False
```

### -ProgressAction
@{Text=}

```yaml
Type: ActionPreference
Expand All @@ -88,14 +93,13 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
## INPUTS

### None

## OUTPUTS

### System.Object
## NOTES
Requires Azure PowerShell (`Az` module).
Requires Azure PowerShell (\`Az\` module).
The target and destination Key Vaults must be in the same subscription and an Azure region within the same geography.
Each exported secret file is named using the format: `<SecretName>-<UnixEpochTimestamp>.<Microseconds>`.
Each exported secret file is named using the format: \`\<SecretName\>-\<UnixEpochTimestamp\>.\<Microseconds\>\`.
The function checks if the Key Vault exists before proceeding.
If no secrets are found in the Key Vault, a warning message is displayed.

Expand Down
Loading