Skip to content

Instantly share code, notes, and snippets.

View JohnL4's full-sized avatar

John Lusk JohnL4

View GitHub Profile
@JohnL4
JohnL4 / Get-ProcessesWithCommandLines.ps1
Last active November 3, 2023 13:50
Get processes WITH COMMAND LINES (must run as admin)
get-process node `
| select id,starttime,name,
@{ Name="CommandLine";
Expr={ $filter = "ProcessId = {0}" -f $_.Id; (Get-CimInstance Win32_Process -filter $filter).CommandLine }} `
| ? {$_.CommandLine -match ' gulp\.js Build_'} `
| sort starttime `
| ft -au -wr
# Omit the filter on gulp.js for a fuller result.
@JohnL4
JohnL4 / Remove-OldSisenseLogs.ps1
Created December 12, 2022 14:56
Sisense log cleanup
# Old log file cleanup
cd C:\ProgramData\Sisense\PrismWeb\Logs
ls *.log.* `
| ? {$_.Extension -match '^\.[0-9]+$' } `
| ? {$_.LastWriteTime -lt (Get-Date).AddMonths(-1)} `
| rm -vb
@JohnL4
JohnL4 / Get-DistributionTime.ps1
Last active September 29, 2022 13:49
Get the time it takes to distribute cubes out of the log files generated by each distribution job
# Skip short files (assumed error outputs), files that contain "already begin built".
# Parse timestamp out of filename (YYYY-MM-DD-HHMMSS).
# Drop first component of "cube name" (the "Build_" part of "Build_Cube_Name")
ls *-2022-09-*.txt `
| ? {$_.Length -gt 1000} `
| ? {-not (sls -list 'already being built' $_)} `
| sls "Finished '(.*)' after (([0-9\.]+) [a-zA-Z]+)" `
| sel -fir 1000 `
| sel @{Name="Timestamp";Expr={if ($_.Filename -match "(?<timestamp>20\d+-\d+-\d+-\d+)") {$Matches.timestamp} else {""}}} `
@JohnL4
JohnL4 / Get-DbConnections.ps1
Created September 26, 2022 21:33
Get d/b connections from Sisense elasticubes
cd N:\SisenseBuilds\Elasticubes
ls */*.xml `
| % {[xml] $xml = cat $_;
# $xml | gm
$xml.Cloud["Cloud.Tables"].Tables.CloudTable `
| % {
# $_ | gm
[PSCustomObject] @{
Server = $_["CloudTable.ConnectionProperties"].SqlServerConnectionProperties.Server;
Database = $_["CloudTable.ConnectionProperties"].SqlServerConnectionProperties.Database
@JohnL4
JohnL4 / Convert-SidToUserName
Created July 28, 2022 13:46
Convert a Windows SID to a user name
# From https://morgantechspace.com/2015/09/convert-sid-to-username-using-powershell.html#:~:text=SecurityIdentifier%20in%20Windows%20PowerShell%20script,to%20security%20identifier%20(SID).
$SID ='S-1-5-21-1924530255-1943933946-939161726-500'
$objSID = New-Object System.Security.Principal.SecurityIdentifier($SID)
$objUser = $objSID.Translate([System.Security.Principal.NTAccount])
Write-Host "Resolved user name: " $objUser.Value
@JohnL4
JohnL4 / Get-jQueryVersions.ps1
Created July 20, 2022 17:59
PowerShell snippet to find out which versions of jQuery you have on your file system
ls jquery* -rec | sls 'jquery.*\b(v[1-9]+(\.[0-9]+(\.[0-9]+)?)?)' | select Filename,@{Name="Version";Expr={ $_.Matches[0].Groups[1].Value}},Path,@{Name="Line";expr={if ($_.Line.Length -gt 1024) { $_.Line.Substring(0,1024)} else {$_.Line}}} | ogv
@JohnL4
JohnL4 / colab-snippets.py
Last active April 22, 2022 15:31
Google colab snippets
from sympy import *
# import numpy as np # Doesn't mix super-well w/sympy
from sympy.plotting import plot # According to https://stackoverflow.com/questions/71519021/what-is-the-difference-between-matplotlib-and-sympy-plotting-module,
# sympy.plotting is an abstraction layer over matplotlib, and is preferred for symbolic stuff.
# import matplotlib.pyplot as plt
init_printing()
from sympy.vector import CoordSys3D, Vector, matrix_to_vector as m2v
N = CoordSys3D('N')
t = symbols('t')
@JohnL4
JohnL4 / parse-xml.ps1
Last active May 18, 2022 15:50
Extract data from multiple XML files, composing into PSCustomObjects which can then be sorted uniquely.
# ls *.xml | % {[xml] $xml = cat $_; $xml.Cloud["Cloud.Tabls"].Tables.CloudTable | % { [PSCustomObject] @{ Server = $_["CloudTable.ConnectionProperties"].SqlServerConnectionProperties.Server; Database = $_["CloudTable.ConnectionProperties"].SqlServerConnectionProperties.Database}}}
ls .\*.xml `
| % {[xml] $xml = cat $_; # Cast to [xml] magically parses XML text into an XmlElement (document).
# $xml | gm # Then you just have to navigate the various children and attributes.
$xml.Cloud["Cloud.Tables"].Tables.CloudTable `
| % {
# $_ | gm
[PSCustomObject] @{ # Cast to [PSCustomObject] "magically" turns a hash into an object w/hash key-value pairs as properties.
Server = $_["Clou
@JohnL4
JohnL4 / File-Cleanup.ps1
Last active March 14, 2022 15:57
File cleanup
$mb = 1024*1024
$days60 = (Get-Date).AddDays(-60)
ls | ? {($_.Length -gt 180*$mb) -and ($_.LastWriteTime -lt $days60)}
# Can pipe above cmd to 'rm -vb'
@JohnL4
JohnL4 / Test-ClockDrift.ps1
Created February 9, 2022 16:37
Check for clock drift on various machines (could affect JWT token validity)
foreach ($mach in @($env:COMPUTERNAME,"p8sismnweb03s","p8sismnbld01s","p8cstweb01d","p8cstweb01p")) {
Write-Host -fore cyan $mach
icm $mach {get-date}
}