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.
Use the -match
with your regex and find the matches in the build-in $matches
hash table!
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.
Use the -match
with your regex and find the matches in the build-in $matches
hash table!
function disableResiliency { | |
param( | |
[Parameter(Mandatory = $true)] | |
[string]$AddinName, | |
[Parameter(Mandatory = $false)] | |
[switch]$Force, | |
[Parameter(Mandatory = $false)] | |
[switch]$AllowUserControl | |
) | |
$AddinList = $null |
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 | |
} |
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 |
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 |
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 |
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) { |
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 |
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 |
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 |