This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.mode columns | |
.headers on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Wrap your entire script in a try-catch block: | |
try { | |
# Do stuff | |
} | |
catch { | |
Write-Error ("{0}`n{1}" -f $_, $_.ScriptStackTrace) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$f = ls foo/bar.txt | |
$f | select Directory,DirectoryName,BaseName,Extension | |
# More generic than just filesystem provider (e.g., registry keys) | |
$f | split-path -parent # Container | |
$f | split-path -leaf # Contained child |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$machDrives = @( | |
# [PSCustomObject] @{ mach = "\\P8SisWeb02x\C$"; drive = "X:" }, | |
# [PSCustomObject] @{ mach = "\\P8SisWeb01d\C$"; drive = "E:" }, | |
# [PSCustomObject] @{ mach = "\\P8SisWeb01q\C$"; drive = "Q:" }, | |
# [PSCustomObject] @{ mach = "\\P8SisMnBld01s\C$"; drive = "H:" }, | |
# [PSCustomObject] @{ mach = "\\P8SisMnWeb01s\C$"; drive = "I:" }, | |
# [PSCustomObject] @{ mach = "\\P8SisMnWeb02s\C$"; drive = "J:" }, | |
# [PSCustomObject] @{ mach = "\\P8SisMnWeb03s\C$"; drive = "K:" }, | |
# [PSCustomObject] @{ mach = "\\P8SisBld01t\C$"; drive = "L:" }, | |
# [PSCustomObject] @{ mach = "\\P8SisWeb01t\C$"; drive = "M:" }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ls Collabor8*/*Collabor8*.ecube -rec | sel LastWriteTime,Length,@{N="Owner";E={$_.GetAccessControl().Owner}},FullName | ft -au -wr | |
# Note the nested {} on the expr value (code block?). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---------------------------- Left outer join -------------------------------------------------------------------- | |
var ecpNodes = | |
(from cp in _db.CustomerProduct | |
join ec in _db.EnvironmentCustomer on cp.CustomerId equals ec.CustomerId | |
join ecp in _db.EnvironmentCustomerProduct | |
on new { ec.EnvironmentId, cp.CustomerId, cp.ProductId } | |
equals new { ecp.EnvironmentId, ecp.CustomerId, ecp.ProductId } | |
into gj | |
// This idiom (group join, then 2nd "from" .DefaultIfEmpty()) results in a left outer join on ECP: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get-service sisense* | select Status,Name,StartType | ft -au -wr | |
Get-CimInstance -ComputerName p8SisMnWeb01s,p8SisMnWeb02s,p8SisMnWeb03s -ClassName Win32_Service ` | |
| ? {$_.Name -match 'sisense.*'} ` | |
| select PSComputerName,State,ProcessID,Name,StartMode,StartName ` | |
| sort PSComputerName,Name ` | |
| ft -au -wr | |
ps *Sisense*,*Elasticube* | select ProcessName,StartTime,Path,Description | sort StartTime -desc | ft -au -wr | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# Writes a registry entry to swap caps lock and left control permanently. This affects all users and the login screen, and doesn't | |
require any other software to run after this (e.g., PowerToys). Requires a reboot after this script is run to take effect. | |
Courtesy of https://www.mavjs.org/post/swap-ctrl-and-capslock-on-windows/ | |
#> | |
$hexified = "00,00,00,00,00,00,00,00,03,00,00,00,1d,00,3a,00,3a,00,1d,00,00,00,00,00".Split(",") | % { "0x$_"}; | |
$kbLayout = 'HKLM:\SYSTEM\CurrentControlSet\Control\Keyboard Layout'; | |
New-ItemProperty -Path $kbLayout -Name "Scancode Map" -PropertyType Binary -Value ([byte[]]$hexified) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cat scheduled-task-2021-05-25.log ` | |
| sls 'Probe foo_.*' ` | |
| % {$_.Matches[0].Captures[0].Value} ` | |
| sort -uniq | |
<# | |
Matches is array of matches in line (could be multiple, for repeated occurrences of the pattern). | |
Groups is regexp capture groups, [0] is entire matched string (I guess) | |
#> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Hard to search when you don't know the right keywords. | |
get-service ` | |
| select @{name="DependentServiceName";expr={$_.Name}} -expand ServicesDependedOn ` | |
| select DependentServiceName,Name ` | |
| sort DependentServiceName,Name ` | |
| ft -au -wr | |