Skip to content

Instantly share code, notes, and snippets.

@avvi00
avvi00 / Get-CWMetrics.ps1
Last active January 10, 2018 01:02
Get EC2 cloudwatch metric for instance in powershell
enum MetricStat {
Minimum
Maximum
Average
SampleCount
Sum
}
$metricName = 'CPUCreditBalance'
$instance = 'zzzzzzzzzzz'
@avvi00
avvi00 / Read-S3Log.ps1
Created February 1, 2017 03:07
Reads s3 access logs from piped input and outputs powershell objects that can then be grouped/sorted
$pat = '(?<BucketOwner>\S+) (?<BucketName>\S+) \[(?<Time>.*?)] (?<RemoteIp>\S+) (?<Requester>\S+) (?<RequestId>\S+) (?<Operation>\S+) (?<ObjectKey>\S+) (?<RequestUri>"([^"]+))" (?<HttpStatus>\S+) (?<ErrorCode>\S+) (?<BytesSent>\S+) (?<ObjectSize>\S+) (?<TotalTime>\S+) (?<TurnaroundTime>\S+) (?<Referrer>\S+) (?<UserAgent>"([^"]+)") (?<VersionId>\S+)'
$regEx = New-Object System.Text.RegularExpressions.Regex($pat)
$dict = @{}
$names = $regEx.GetGroupNames()
$indexes = $regEx.GetGroupNumbers()
for($i = 0; $i -lt $names.Length; $i++) {
@avvi00
avvi00 / Get-InstanceSecurityGroups
Created April 21, 2016 12:28
Get a collection of ec2 instance names (from tag) with associated security groups
Get-EC2Instance |
Select -ExpandProperty Instances |
Select -Property @{
Name='InstanceId'
Expression={$_.InstanceId}
},
@{
Name='SecurityGroups'
Expression = {$_.SecurityGroups | Select -ExpandProperty GroupId}
},
@avvi00
avvi00 / Get-AllPrivateBitbucketRepos.ps1
Last active February 11, 2020 08:51
Powershell script to enumerate all repos in your bitbucket account
$account = 'zzz'
$userPass = 'username:password'
$basicAuthHeader = "Basic " + [System.Convert]::ToBase64String( ([System.Text.ASCIIEncoding]::ASCII.GetBytes($userPass)))
$repo = Invoke-RestMethod "https://api.bitbucket.org/2.0/repositories/$account" -Headers @{Authorization = $basicAuthHeader}
$repos = @()
while ($repo.next) {
$repos += $repo