Skip to content

Instantly share code, notes, and snippets.

View rleap-m's full-sized avatar

Ryan Leap rleap-m

  • Mirantis
  • Raleigh, NC
View GitHub Profile
@rleap-m
rleap-m / keybase.md
Created August 3, 2020 20:11
Gist for Keybase identity verification

Keybase proof

I hereby claim:

  • I am rleap-m on github.
  • I am rleap (https://keybase.io/rleap) on keybase.
  • I have a public key ASDmUr9Pekse16W1M6EMQOlYz-FGrJsP09ax2CrxYK5ytwo

To claim this, I am signing this object:

@rleap-m
rleap-m / SplitMethodPowerShellVer5VsVer7.ps1
Last active August 12, 2020 16:59
.Split() Method behaving differently in PowerShell v5 and v7 - causing issue with Docker install.ps1
# Try running this in PowerShell 5 and then in PowerShell 7 - you'll see different behavior
# with the .Split() method
$PSVersionTable.PSVersion
$tab = [char]9
$hasTab = "[$tab]"
$hasTabAndSpace = "[$tab ]"
$hasTab
$hasTabAndSpace
$hasTab.Split(' ')
@rleap-m
rleap-m / Show-FirewallRulesForDockerWithPorts.ps1
Last active December 7, 2020 20:25
Docker Firewall Rules
Get-NetFirewallRule -DisplayName '*docker*' |
ForEach-Object { $ports = Get-NetFirewallPortFilter -AssociatedNetFirewallRule $_;
Select-Object -InputObject $_ -Property DisplayName,Enabled,Profile,Direction,Action,
@{Name='Protocol'; Expression={$ports.Protocol}},@{Name='LocalPort'; Expression={[int64]$ports.LocalPort}} } |
Sort-Object -Property LocalPort | Format-Table
@rleap-m
rleap-m / BindMountContainerExample.ps1
Last active September 6, 2022 15:12
Using Volumes on Windows - Bind Mount (aka Host Mount) Container Example
# This is a 'Bind Mount' (as opposed to a Named volume which is managed by Docker)
# https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/persistent-storage
# Linux - SELinux - make sure your mount point isn't something like /home or /usr
docker container run --rm -it -v "$(pwd)"/containerdata:/data:Z rleapm/mke-mgmt:lnx-1.2
# Windows
@rleap-m
rleap-m / WindowsContainerCheckMyHealth.ps1
Last active September 11, 2020 17:10
Example of a container with a health check
# Command line to run a PowerShell encoded command (allows you to avoid escaping special characters)
$runPoshEncodedCmd = 'powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand '
# Command to run in the container - loop which outputs the date to a file and STDOUT
$command = "& { Write-Host `"The working directory is [`$(`$pwd.Path)]`";"
$command += " `$null = New-Item -Path c:\temp\ -ItemType Directory -ErrorAction SilentlyContinue;"
$command += " do { Get-Date -Format s | Tee-Object -FilePath C:\Temp\date_output2.txt -Append;"
$command += " Write-Host `"Line count: `$((Get-Content -Path C:\Temp\date_output2.txt).Count)`";"
$command += " Start-Sleep -Seconds 5} while (`$true) }"
@rleap-m
rleap-m / EventLogBackup.ps1
Last active September 11, 2020 20:46
A script which can export Windows classic event logs (Application, System, Security) to an evtx file
# Followed this article: https://www.thomasmaurer.ch/2011/05/powershell-how-to-export-windows-eventlogs-with-powershell/
[CmdletBinding()]
param (
[Parameter(Mandatory=$false)]
[ValidateSet('Application','HardwareEvents','Security','System','Windows PowerShell')]
[string] $LogFileName = 'Application'
)
$exportFileName = Join-Path -Path $ENV:TEMP -ChildPath ($ENV:COMPUTERNAME + '_' + $logFileName + "_" + "$(Get-Date -f yyyyMMdd).evtx")
[System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain()
<#
.SYNOPSIS
Generates a password
.PARAMETER Length
Number of characters that should be in the password
.PARAMETER NonAlphaMinCount
The minimum number of non-alphanumeric characters (such as @, #, !, %, &, and so on) in the generated password
.NOTES
[email protected]
#>
@rleap-m
rleap-m / DockerContainerStatusLoopCsv.ps1
Last active August 22, 2024 05:12
Collects 'docker container ls' output and outputs it to a CSV
$sleepTimeSec = 10 # Sleep between data collection iteration
$durationinMin = 2 # Collect data for this many minutes
# Delete the previous file
$csvPath = '.\watch-container-status.csv'
if (Test-Path -Path $csvPath -PathType Leaf) {
Remove-Item -Path $csvPath
}
@rleap-m
rleap-m / GetEventLogEventsAsCsv.ps1
Last active September 17, 2021 18:34
PowerShell commands to get events from event logs
Write-Host "Exporting the Application Event Log..."
Get-EventLog -LogName Application | Sort-Object -Property TimeGenerated -Descending |
Export-Csv -NoTypeInformation -Path ".\$($ENV:COMPUTERNAME)_Event-Log-Application.csv"
Write-Host "Exporting the System Event Log..."
Get-EventLog -LogName System | Sort-Object -Property TimeGenerated -Descending |
Export-Csv -NoTypeInformation -Path ".\$($ENV:COMPUTERNAME)_Event-Log-System.csv"
Write-Host "Exporting the Host Compute Service Admin Event Log..."
Get-WinEvent -LogName Microsoft-Windows-Hyper-V-Compute-Admin | Sort-Object -Property TimeCreated -Descending |