Created
May 1, 2024 17:06
-
-
Save jschlackman/1436114a85cdd6c02696a8bedb60b1e8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Name: Get-AzureStorageEncryptionDetails.ps1 | |
# Author: James Schlackman | |
# Last Modified: May 1 2024 | |
# | |
# Lists all storage accounts with their encryption settings. | |
#Requires -Modules Az.Accounts, Az.Storage | |
Param( | |
[Parameter()] [String] $AzTenant, | |
[Parameter()] [String] $AzSubscription, | |
[Parameter()] [String] $OutputPath = "$((Get-Date).ToString("yyMMdd")) Azure Storage Accounts" | |
) | |
# Connect to Azure | |
Connect-AzAccount | |
# Set context to specified tenant or subscription if provided | |
If ([bool]$AzTenant) { | |
Set-AzContext -Subscription $AzTenant | |
} ElseIf ([bool]$AzSubscription) { | |
Set-AzContext -Subscription $AzSubscription | |
} | |
$storageAccounts = Get-AzStorageAccount | Sort-Object -Property ResourceGroupName, StorageAccountName | |
$AuditOutput = $storageAccounts | ForEach-Object { | |
[PSCustomObject]@{ | |
StorageAccountName = $_.StorageAccountName | |
ResourceGroupName = $_.ResourceGroupName | |
PrimaryLocation = $_.PrimaryLocation | |
SkuName = $_.Sku.Name | |
Kind = $_.Kind | |
AccessTier = $_.AccessTier | |
CreationTime = $_.CreationTime | |
EnableHttpsTrafficOnly = $_.EnableHttpsTrafficOnly | |
EncryptionEnabled = $_.Encryption.Services.File.Enabled | |
EncryptionEnabledTime = $_.Encryption.Services.File.LastEnabledTime | |
EncryptionKeyType = $_.Encryption.Services.File.KeyType | |
} | |
} | |
# Display output | |
$AuditOutput | Out-GridView -Title ("Storage acccounts for subscription {0} ({1})" -f (Get-AzContext).Subscription.Name, (Get-AzContext).Subscription.TenantId) | |
Write-Host 'See grid export for details.' | |
# Optionally export output to file | |
Write-Host "`nExport details to CSV? " -ForegroundColor Cyan -NoNewline | |
$OutputPath = "$OutputPath - {0}.csv" -f (Get-AzContext).Subscription.TenantId | |
If ((Read-Host '[y/N]').ToUpper() -eq 'Y') { | |
Write-Host 'Exporting to ' -NoNewline | |
Write-Host $OutputPath -ForegroundColor Green | |
$AuditOutput | Export-Csv -NoTypeInformation -Path ($OutputPath) -Encoding UTF8 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment