Skip to content

Instantly share code, notes, and snippets.

View pkutaj's full-sized avatar

pavol kutaj pkutaj

View GitHub Profile
@pkutaj
pkutaj / powershell regex matches.md
Created August 19, 2019 16:16
powershell regex matches.md

THE CASE OF WORK WITH REGEX MATCHES

the case

the puzzle is, how to assign a match in regex search to a new variable: to test-path it and eventually create a folder, if the test fails.

solution

Use the -match with your regex and find the matches in the build-in $matches hash table!

sources

@pkutaj
pkutaj / Force-OutlookAddinLoad.ps1
Last active December 30, 2021 11:03
Force Load Outlook Addin
function disableResiliency {
param(
[Parameter(Mandatory = $true)]
[string]$AddinName,
[Parameter(Mandatory = $false)]
[switch]$Force,
[Parameter(Mandatory = $false)]
[switch]$AllowUserControl
)
$AddinList = $null
@pkutaj
pkutaj / create-codeFiles.ps1
Last active February 24, 2021 03:49
Create Code Files, Test Files, and Link them
function create-codeFiles($name, $testName, $extension, $linkText) {
$codeFile = ("$name" -replace "\s", "_") -replace ".+", "$&.$extension"
$testFile = ("$name" -replace "\s", "_") -replace ".+", "$&$testName.$extension"
New-Item $codeFile -ErrorAction Ignore
New-Item $testFile -ErrorAction Ignore
Add-Content $testFile -Value $linkText
code .
Invoke-Item $codeFile
Invoke-Item $testFile
}
@pkutaj
pkutaj / test-certificate.ps1
Created February 19, 2021 09:04
test-certificate.ps1
function test-certificate($domain, $contextLength = 10) {
$cacertPath = "c:\cacert.pem"
$domain += ":443"
echo "q" | openssl s_client -connect $domain -CAfile $cacertPath | openssl x509 -noout -enddate | sls "notAfter.*"
echo "q" | openssl s_client -connect $domain -CAfile $cacertPath | sls "certificate chain" -Context $contextLength
Write-Host "~~~" -ForegroundColor darkcyan
Write-Host "→ If needed, pass a desired output length after domainname" -ForegroundColor darkcyan
Write-Host "→ To update the list of trusted Certificates, run:" -ForegroundColor darkcyan
Write-Host "→ Invoke-WebRequest https://curl.se/ca/cacert.pem -OutFile 'c:\cacert.pem'" -ForegroundColor darkcyan
@pkutaj
pkutaj / getMillis.ps1
Created February 20, 2021 02:17
Convert Unix Timestamp (with millisecond!) to Local time
function getMillis {
param (
$unixTimeStamp
)
$epochStart = Get-Date 01.01.1970
$millisStamp = ($epochStart + ([System.TimeSpan]::frommilliseconds($unixTimeStamp))).ToLocalTime()
$millisStampOutput = $millisStamp.ToString("yyyy-MM-dd HH:mm:ss.ffffff")
$millisStampClipboard = $millisStamp.ToString("HH:mm:ss.ffffff")
Write-Host "~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
Write-Host "Datetime: $millisStampOutput" -ForegroundColor Cyan
@pkutaj
pkutaj / spagettiNomad.ps1
Last active February 24, 2021 09:57
spagettiNomad
function get-nomadLogs ($jobId, $featureFlag) {
$nomadLogs = ($featureFlag -ne "e") ?
(nomad alloc logs -job $jobId) :
(nomad alloc logs -stderr -job $jobId)
if ($featureFlag -eq "l") { oh -InputObject $nomadLogs }
if (nomad status $jobID | sls -Pattern "(?=.*\d)failed") {
write-host "Job Failed - see webUI - stderr below" -ForegroundColor DarkRed
@pkutaj
pkutaj / refactoredNomad.ps1
Created February 24, 2021 09:56
refactoredNomad
function get-nomadLogs ([string]$jobId, [string]$featureFlag) {
function get-stderr ($jobId) {
$nomadLogs = nomad alloc logs -stderr -job $jobId
if (nomad status $jobID | Select-String status.*dead) {
Out-Host -InputObject $nomadLogs
}
}
function get-logs($jobId) {
@pkutaj
pkutaj / query-consul.ps1
Created March 3, 2021 11:44
query-consul.ps1
function query-consul ([string]$customer, [string]$queryString, [int]$context, [switch]$detailed) {
$consulURL = "https://consul.foo.net/ui/eu-central-1/kv/customer/$customer"
elseif ($detailed) {
consul kv get -recurse -detailed customer/$customer |
Select-String $queryString -Context 1, $context
}
else {
consul kv get -recurse customer/$customer |
Select-String $queryString -Context 1, $context
@pkutaj
pkutaj / downloadCert.ps1
Created March 12, 2021 04:17
PowerShell's script to validate / download OpenSSL certificate
function test-certificate($domain, $contextLength = 10, [switch]$download) {
$cacertPath = "c:\cacert.pem"
$connectDomain = $domain + ":443"
#<feature> download certificate into a download folder
if($download) {
echo "q" | openssl s_client -servername $domain -connect $connectDomain -CAfile $cacertPath |
openssl x509 -text |
out-file "C:\Users\$env:USERNAME\downloads\$domain.txt" -force
Write-Host "~~~" -ForegroundColor darkcyan
@pkutaj
pkutaj / dailyChronicle.ps1
Created March 20, 2021 00:14
dailyChronicle.ps1
function backup {
cd $kronFolder
$today = $today.ToString("yyyy-MM-dd")
git add . && git commit -m "$today" && git push
}
function add-imageFromYesterday {
$span = (($today).DayOfWeek -ne "Tuesday") ? 1 : 3
$i = 1