Get AWS snapshot report into Excel (Powershell script)


Snapshots are accruing more cost in aws field. Time to time we need to do clean up snapshots as cost optimisation process.

This power-shell scripts helps to get the list of snapshots in to excel in particular AWS account  . 

This script helps to get EC2 snapshots details into CSV file with following fields. The CVS file is creating with the name of current date.
- VolumeID
- SnapshotID
- Size
- Description
- Starttime
- State
- Encryption
- OwnerID

Pre-requirements to run the script

AWS_Profile_Name
aws credential file needs to be updated with aws_access_key_id and aws_secret_access_key. The aws config file is in C:\Users\user_profile_name\.aws\credentils.


location to save file_

Give the location of you computer  to save the Excel file
ex: D:\Snapshot Report\


Output








Script

✔️

#--Get Snapshot Report ( Soretd with stated date)--# $cpmsnapshots = get-ec2snapshot -ProfileName "AWS_Profile_Name" -Region region -OwnerId 'aws account ID' $sorted = $cpmsnapshots | Sort-Object -Property StartTime write-host "Sorting Completed" -ForegroundColor Gray $date=get-date -uFormat "%d%m%Y" $Filename = "location to save file_" + $date.ToString() +".csv" $SnapshotReport = @() foreach ($snapshot in $Sorted) { $tags=$snapshot.Tag foreach ( $tag in $tags) { if( $tag.key -eq 'Name'){ $Name = $tag.value } } $volumeId = $snapshot.VolumeId $snapshotID= $snapshot.SnapshotId $size = $snapshot.VolumeSize $Description = $snapshot.Description $starttime = $snapshot.StartTime $state = $snapshot.state $encryption = $snapshot.Encrypted $OwnerID = $snapshot.OwnerId $record = New-Object System.object $record | Add-Member -Type NoteProperty -Name Tag-Name -value $Name -Force $record | Add-Member -Type NoteProperty -Name VolumeId -value $volumeId -Force $record | Add-Member -Type NoteProperty -Name Snapshot_ID -value $snapshotID -Force $record | Add-Member -Type NoteProperty -Name Size -value $size -Force $record | Add-Member -Type NoteProperty -Name Description -value $Description -Force $record | Add-Member -Type NoteProperty -Name StartTime -value $starttime -Force $record | Add-Member -Type NoteProperty -Name State -value $state -Force $record | Add-Member -Type NoteProperty -Name Encryption -value $encryption -Force $record | Add-Member -Type NoteProperty -Name OwnerID -value $OwnerID -Force $SnapshotReport = $SnapshotReport + $record } write-host "Generating Report " -ForegroundColor yellow $SnapshotReport | export-csv $Filename Write-host "Report Generated in " $Filename -ForegroundColor Green

Comments

Popular posts from this blog

Install LDAP /SSL certificates in single/multiple Servers (Powershell script)

Recycle IIS app pools in EC2 instance on application load balances (Powers-hell script)