Skip to content

Instantly share code, notes, and snippets.

Avatar

pavol kutaj pkutaj

View GitHub Profile
@pkutaj
pkutaj / powershell regex matches.md
Created Aug 19, 2019
powershell regex matches.md
View 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 Dec 30, 2021
Force Load Outlook Addin
View Force-OutlookAddinLoad.ps1
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 Feb 24, 2021
Create Code Files, Test Files, and Link them
View create-codeFiles.ps1
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 Feb 19, 2021
test-certificate.ps1
View 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 Feb 20, 2021
Convert Unix Timestamp (with millisecond!) to Local time
View getMillis.ps1
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
View spagettiNomad.ps1
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
View refactoredNomad.ps1
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) {
View 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 Mar 12, 2021
PowerShell's script to validate / download OpenSSL certificate
View downloadCert.ps1
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
View 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