daily pastebin goal
66%
SHARE
TWEET

Untitled

a guest Jun 12th, 2016 248 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. #
  2. # AWS Report
  3. #
  4. # Requires AWS plugin: https://aws.amazon.com/powershell/
  5. # Set-AWSCredentials -AccessKey <access key> -SecretKey <secret key> -Storeas <profile name>
  6. # Full instructions found http://i-script-stuff.electric-horizons.com/?p=43&preview=true
  7. #
  8. #
  9.  
  10. #Just a quick check for powershell 3.0 and older:
  11. if($PSVersionTable.PSVersion.Major -ge 4) {
  12. Import-Module AWSPowerShell
  13. } else {
  14. Import-Module "C:\Program Files (x86)\AWS Tools\PowerShell\AWSPowerShell\AWSPowerShell.psd1"
  15. }
  16.  
  17. #profiles to check
  18. $profile_list = ("Example_1")
  19.  
  20.  
  21. #Path configs
  22. $website_path = "C:\inetpub\awsreport.html"
  23. $website_tmp_path = ".\awsreport.tmp"
  24. $csv_tmp_path = ".\awscsvreport.tmp"
  25. $csv_path = "C:\inetpub\awsreport.csv"
  26.  
  27. echo "<html>
  28.       <head>
  29.       <title>AWS Report</title>
  30.       </head>
  31.       <body>
  32.     <style style=""text/css"">
  33.     .hoverTable{
  34.         width:100%;
  35.         border-collapse:collapse;
  36.     }
  37.     .hoverTable th {
  38.         padding:8px; border:#4e95f4 1px solid;background-color: #B4CDCD
  39.     }
  40.    
  41.     }
  42.     .hoverTable td{
  43.         padding:7px; border:#4e95f4 1px solid;
  44.     }
  45.     /* Define the default color for all the table rows */
  46.     .hoverTable tr{
  47.         background: #b8d1f3;
  48.     }
  49.     /* Define the hover highlight color for the table row */
  50.    .hoverTable tr:hover {
  51.          background-color: #ffff99;
  52.    }
  53. </style>
  54.  
  55. <table class=""hoverTable"">" > $website_tmp_path
  56. echo """Environment"",""Region"",""Instance Name"",""Instance ID"",""Instance Type"",""Powered State"",""Private IP Address"",""Public IP Address"", ""Security Groups""" > $csv_tmp_path
  57.  
  58. foreach($profile in $profile_list) {
  59. echo "<tr><th>Environment</th><th>Region</th><th>Instance Name</th><th>Instance ID</th><th>Instance Type</th><th>Powered State</th><th>Private Ip Address</th><th>Public Ip Address</th><th>Security Groups</th></tr>" >> $website_tmp_path
  60. Set-AWSCredentials -ProfileName $profile
  61. $region_list = Get-AWSRegion | select -expandproperty Region
  62.  
  63.     foreach($region in $region_list) {
  64.     $Instance_list = Get-EC2Instance -region $region |select -expandproperty instances
  65.  
  66.     $VPC_list = Get-EC2Vpc -Region $region
  67.         foreach ($VPC in $VPC_list) {
  68.         $Instance_list | Where-Object {$_.VpcId -eq $VPC.VpcId} | foreach-object {
  69.             $Instance_name = ($_.Tags | Where-Object {$_.Key -eq 'Name'}).Value
  70.             $Instance_id = $_.InstanceId
  71.             $InstanceType = $_.InstanceType
  72.             $Private_ip = $_.PrivateIpAddress
  73.             $Public_ip = $_.PublicIpAddress
  74.             $Power_State = $_.State.Name
  75.             $SecurityGroups = $_.SecurityGroups.GroupName
  76.             echo "$Profile,$Region,$Instance_name,$Instance_id,$InstanceType,$Power_State,$Private_ip,$Public_ip,$SecurityGroups"
  77.             echo """$Profile"",""$Region"",""$Instance_name"",""$Instance_id"",""$InstanceType"",""$Power_State"",""$Private_ip"",""$Public_ip"",""$SecurityGroups""" >> $csv_tmp_path
  78.             echo "<tr><td>$Profile</td><td>$Region</td><td>$Instance_name</td><td>$Instance_id</td><td>$InstanceType</td><td>$Power_State</td><td>$Private_ip</td><td>$Public_ip</td><td>$SecurityGroups</td></tr>" >> $website_tmp_path
  79.             }
  80.         }
  81.     }
  82. }
  83. echo "</table></body></html>" >> $website_tmp_path
  84. move-item $website_tmp_path $website_path -Force
  85. move-item $csv_tmp_path $csv_path -Force
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top