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
| #!/usr/local/bin/bash | |
| XXX=$(aws ec2 describe-instances \ | |
| --filters "Name=tag-key,Values=Name" \ | |
| --query 'Reservations[*].Instances[*].{Instance:InstanceId, Type:InstanceType, Platform:Platform, Volumes:BlockDeviceMappings[*].Ebs.VolumeId, NetworkInterfaces:PrivateIpAddress,AZ:Placement.AvailabilityZone, Name:Tags[?Key==`Name`]|[0].Value}' \ | |
| --output json) | |
| echo "$XXX" > xxx.json |
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
| #!/bin/bash | |
| aws ec2 describe-instances \ | |
| --filter "Name=instance-state-name,Values=stopped" \ | |
| --query "Reservations[*].Instances[*].[PublicIpAddress, Tags[?Key=='Name'].Value|[0]]" \ | |
| --output text | grep -v "None" |
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
| #!/bin/bash | |
| # Find the sizes of the S3 buckets in your account. | |
| for name in $(aws s3api list-buckets --query 'Buckets[*].Name' --output text); do | |
| size=$(aws cloudwatch get-metric-statistics --namespace AWS/S3 --metric-name BucketSizeBytes --start-time $(date --date="yesterday" +%Y-%m-%d) --end-time $(date +%Y-%m-%d) --period 86400 --statistics Maximum --dimensions Name=BucketName,Value=$name Name=StorageType,Value=StandardStorage --query 'Datapoints[0].Maximum' | sed 's/null/0.0/' | cut -d. -f1) | |
| if [[ $size -eq 0 ]]; then | |
| echo "$name" | |
| fi | |
| done |
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
| #!/bin/bash | |
| # Find self-owned AMI's which are not used by any instances or launch | |
| # configurations in the default region. | |
| # | |
| # Output with details in descending order by name, creation date | |
| aws ec2 describe-images --image-ids \ | |
| $(comm -23 \ | |
| <(aws ec2 describe-images --owner self --query 'Images[].[ImageId]' --output text | sort) \ | |
| <(( | |
| aws ec2 describe-instances --query 'Reservations[].Instances[].[ImageId]' --output text |
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
| #!/bin/bash | |
| # Find self-owned AMIs that are not used by any instances | |
| # or any launch configurations in the default region. | |
| comm -23 \ | |
| <(aws ec2 describe-images --owner self --query 'Images[].[ImageId]' --output text | sort) \ | |
| <(( | |
| aws ec2 describe-instances --query 'Reservations[].Instances[].[ImageId]' --output text | |
| aws autoscaling describe-launch-configurations --query 'LaunchConfigurations[].[ImageId]' --output text | |
| ) | sort -u) |
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
| import-module ActiveDirectory | |
| $Search_Criteria = "*SMPTest.*" | |
| $AD_Server = "dc1.msad.local" | |
| Get-ADUser -Server $AD_Server -Filter 'SamAccountName -like $Search_Criteria' -Properties Enabled, whencreated, whenchanged, EmailAddress, Company, LockedOut,Description, MemberOf | <# Filter on Extended Property 'Enabled' for all Active users #> where-object enabled -eq $True| Select-Object Name, whencreated,whenchanged, SamAccountName, EmailAddress, Company, Description,LockedOut,MemberOf, Enabled | Format-Table -Wrap Name,whencreated,whenchanged,SamAccountName, EmailAddress, Company, Description,LockedOut, Enabled, MemberOf -A | |
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
| <# | |
| .SYNOPSIS | |
| Mounts a SMB Global Mapping patth with the supplied credentials | |
| .DESCRIPTION | |
| Mounts a Global SMB Mapping path to the server this script is run on. | |
| Usually used on servers that host docker containers that require | |
| persistent data storage that resides on a network resource. |
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
| { | |
| "Version": "2012-10-17", | |
| "Statement":[ | |
| { | |
| "Sid":"AllowListBucketIfSpecificPrefixIsIncludedInRequest", | |
| "Action":["s3:ListBucket"], | |
| "Effect":"Allow", | |
| "Resource":["arn:aws:s3:::my-bucket"], | |
| "Condition":{ | |
| "StringLike":{"s3:prefix":["prod/*"] |
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
| #!/bin/sh | |
| # remove x if you don't want to see the commands | |
| set -ex | |
| # Some variable initialisation with sane defaults | |
| DRUN='--dry-run' | |
| DO_DELETE=${1:-'no'} | |
| REGION=${2:-'eu-west-1'} | |
| ACCOUNTID=${3:-'self'} |
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
| Param( $AWSRegion = 'us-east-1', $AWSProfileName = 'default') | |
| # | |
| # Store your AWS credentials using the following Powershell AWS command: | |
| # | |
| # Set-AWSCredentials -AccessKey {xx} -SecretKey {xx} -StoreAs {MyProfileName} | |
| # | |
| # Example: | |
| # | |
| # Set-AWSCredentials -AccessKey 'AKIAVJL...KWJKOB4XN' -SecretKey 'oxLcrpnd3S+...1Y5eg3m92E8e2Me' -StoreAs 'testprofile' | |
| # Set-DefaultAWSRegion us-east-1 |