Skip to content

Instantly share code, notes, and snippets.

@jrich523
jrich523 / age.ps1
Created January 2, 2022 23:42
Age handling close to how K8s show pod ages for PowerShell
class Age : System.IComparable {
[datetime]$CreationTime
static hidden [regex] $regex = [regex]'^(\d+\w)+$'
age([datetime]$CreationTime){
$this.CreationTime = $CreationTime
$this.SharedConstructor()
}
age([String]$CreationTime){
[Parameter(Mandatory=$true,
Position=0,
ParameterSetName='P1')]
[ValidatePattern("\w{2,5}")]
[string]
$Board,
# Param2 help description
[Parameter(Mandatory=$true,
Position=1,
## Global Values
$pathSplitRegex = "[\\|/]"
<#
.Synopsis
Short description
.DESCRIPTION
Long description
.EXAMPLE
<#
.Synopsis
Short description
.DESCRIPTION
Long description
.EXAMPLE
Example of how to use this cmdlet
.EXAMPLE
Another example of how to use this cmdlet
#>
@jrich523
jrich523 / gist:77aae37d970bbdaa0e2405d956ff5ee6
Last active August 23, 2019 19:30
Find all projects within a folder (recursive)
function find-Projects {
param(
$root='D:\Repos',
$depth = 5)
$projectTypes = @(".git",".vscode")
## is this folder a project?
if(ls $root -Directory -Name -Force | ? { $projectTypes -contains $_})
{
properties([
parameters([
string(name: 'DEPLOY_TEXT', defaultValue: 'defVal', description: '')
])
])
echo "direct value: ${DEPLOY_TEXT}"
echo "param value: ${params.DEPLOY_TEXT}"
if(DEPLOY_TEXT == 'justin') {
currentBuild.result = 'FAILURE'
}
List folders = [
'twelve-factor/Jenkinsfile',
'build-and-publish/Jenkinsfile',
'deploy-and-test/Jenkinsfile',
'deploy-with-redis/Jenkinsfile',
'locust-perf-test/Jenkinsfile',
'deploy-selenium-grid/Jenkinsfile',
'ami/Jenkinsfile'
]
Map subJobs = [:] // name:closure
#ls -l from by-uuid
lrwxrwxrwx. 1 root root 9 Apr 11 21:47 2018-11-25-21-21-31-00 -> ../../sr0
lrwxrwxrwx. 1 root root 10 Apr 11 21:47 6e22e4ee-b81c-48c3-a978-8a49b161786d -> ../../sdal
lrwxrwxrwx. 1 root root 10 Apr 11 21:47 7984825e-cl5d-4707-a86d-67c4851388a9 -> ../../dm-2
lrwxrwxrwx. 1 root root 10 Apr 11 21:47 a866bb05-1b4d-49c4-9ca3-fdla4f111a0c -> ../../dm-1
lrwxrwxrwx. 1 root root 10 Apr 11 21:47 eee8e1b7-9e17-480-ade5-a24d4211c29d -> ../../dm-3
following these directions
$paths = foreach($c in $class){
$p = Join-Path $base (join-path $c "apps")
foreach($a in $app){
$p = join-path $p $a
foreach($e in $env){
Join-Path $p $e
}
}
}
@jrich523
jrich523 / show-psobject.ps1
Created January 4, 2019 18:47
powershell show object advanced
function Show-Object{
param(
## The object to examine
[Parameter(ValueFromPipeline = $true)]
$InputObject
)
#custom controls for treeview... found it on MSDN a while ago, lost link :-/
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')