Skip to content

Instantly share code, notes, and snippets.

@zaqmor
zaqmor / devops-build-notes.md
Created June 5, 2019 21:49
DevOps Build Notes
  1. Build variables should be named starting with a non-reserved prefix, such as triple underscore ('___'), to avoid conflicts...
  • This helps, from other task contexts, to see that this is a custom build variable and not a conflicting devops built in variable or task sub process variable.
@zaqmor
zaqmor / ps-find-files-w-contents-matching-pattern.txt
Created April 18, 2019 21:50
PowerShell: Find files with contents matching pattern
# get-childitem reference: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-childitem?view=powershell-6
Get-ChildItem -recurse -attributes !directory+!compressed+!encrypted+!offline+!reparsepoint | Select-String -pattern "insert-pattern-here" | group path | select name
@zaqmor
zaqmor / git--clean-up-reflog.txt
Last active April 12, 2019 22:07
Cleaning up the git reflog
# Purge the reflog of anything farther back than 180 days, specifying --all, otherwise unreachable 'dangling' objects will be missed,
# optional --expire-unreachable flag could differ on when to expire unreachables
git reflog expire --all --expire=180.days.ago --expire-unreachable=180.days.ago --all
# other examples for expire
--expire=now
--expire=never
--expire="Jan 01 2019"
--expire="2019-01-01 00:00"
@zaqmor
zaqmor / ps-IsDir
Created December 5, 2018 20:16
Powershell: Is item a directory? or Is item a file?
function IsDir { (get-item $args) -Is [System.IO.DirectoryInfo] }
function IsFile { (get-item $args) -Is [System.IO.FileInfo] }
@zaqmor
zaqmor / ps-delete-csproj-output-dirs
Created November 30, 2018 20:23
PowerShell: Delete C# project output directories
get-childitem -recurse -inc "*.csproj" | select-object -expandproperty Directory | select-object -ExpandProperty FullName | get-childitem -recurse -inc bin,obj | ?{$_.PSIsContainer} | select-object -ExpandProperty FullName | remove-item -recurse -force
@zaqmor
zaqmor / ps-get-csproj-paths
Created November 30, 2018 20:20
Powershell: Get all C# projects in a directory as full path strings
get-childitem -recurse -inc "*.csproj" | select-object -expandproperty FullName
@zaqmor
zaqmor / ps-get-sha1-filehash.txt
Created October 26, 2018 17:44
Powershell: Get sha1 filehash
function fsha { get-filehash -algorithm sha1 $args | select-object -ExpandProperty Hash }
@zaqmor
zaqmor / ps-find-file-structure-objects.txt
Last active December 1, 2018 22:39
Powershell: Find file structure object
# https://blogs.technet.microsoft.com/heyscriptingguy/2016/06/27/use-windows-powershell-to-search-for-files/
#
# -r : search recursively through subdirs
# -i "*pattern*" : include files matching pattern, can be used with exclude
# -i "*pattern*" : exclude files matching pattern, can be used with include
# -File : only find files, not dirs?
# -ErrorAction SilentlyContinue : ignore errors, generally, but includes specific minor errors such as files without permissions
# just find file via include
@zaqmor
zaqmor / ps-profile-aliases.txt
Last active December 1, 2018 22:42
PowerShell: Profile aliases
. c:\projects\WebUI-PowershellScripts\profile.ps1
# Chocolatey profile
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}
# list branches matching args, '.' for all else exception
function fbr { git br --all | ss $args }
@zaqmor
zaqmor / ps-get-and-edit-environment-variables.txt
Last active October 22, 2018 23:06
Powershell: Get and edit environment variables
# list ALL
get-childitem Env:
# list one
echo $env:SomeVarName
# edit one
$env:SomeVarName = "value"
# https://www.itprotoday.com/powershell/powershell-one-liner-creating-and-modifying-environment-variable