Skip to content

Instantly share code, notes, and snippets.

View JohnL4's full-sized avatar

John Lusk JohnL4

View GitHub Profile
@JohnL4
JohnL4 / popup-dialog.ps1
Created August 31, 2017 18:39
Show a dialog box from PowerShell w/out first adding DLLs
$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("Operation Completed",0,"Done",0x1)
# From https://blogs.technet.microsoft.com/heyscriptingguy/2014/04/04/powertip-use-powershell-to-display-pop-up-window/
@JohnL4
JohnL4 / play01.ts
Last active August 30, 2017 18:49
Simple horsing around to demonstrate what TypeScript does (paste into playground at typescriptlang.org)
// ============================================================================================
// Typescript is Javascript annotated with type info.
// "Compilation" of Typescript is (in the simple case)
// stripping out the type annotations.
var someNumber: number;
someNumber = 2;
someNumber = "bad"; // Type mismatch
// A slightly fancy way of telling Typescript that this variable is
@JohnL4
JohnL4 / prompt.cmd
Created August 28, 2017 19:15
Reverse-video cmd.exe prompt; might need ANSICON for this to work in Win 7, but it works out of the box in Win 10.
@rem $E - escape
@rem ESC [ 7 m - reverse video
@rem ESC [ 0 m - normal mode
@rem $P - current path
@rem @G - greater-than sign
@rem $S - space
@prompt $E[7m$P$G$E[0m$S
@JohnL4
JohnL4 / scribble.ts
Created July 24, 2017 19:52
In TypeScript playground, a function to write directly to the window, rather than just debugger console.
/**
* Write the given message in a PRE element of the document.
*/
function scribble(aMsg: string): void {
console.log(aMsg);
// Get a reference to the document's PRE element, or null if there isn't one.
var preElt = document.body.querySelector("pre");
if (preElt) {
// Do nothing, we're good
// console.log("got preElt");
@JohnL4
JohnL4 / which.ps1
Created July 13, 2017 20:08
Where is this command coming from?
gcm runonce
gcm runonce | select Definition
# 'gcm' is, by default, aliased to Get-Command
@JohnL4
JohnL4 / Show-Path.ps1
Created July 7, 2017 15:35
Dump out your PATH in a more usable format
$env:PATH -split ";" | less
# 'less' is from PSCX (recommended).
@JohnL4
JohnL4 / Copy-RecentFiles.ps1
Last active July 27, 2017 19:38
Copy files you just built to the application directory for testing.
$build = "7.3.5941.0";
$dest = "c:\Program Files (x86)\Allscripts Sunrise\Clinical Manager Client\$build";
$src = "c:\work\sxa\main\Projects/bin";
ls $src | ? {$_.LastWriteTime -ge (Get-Date).AddMinutes( -5)} | cp -dest $dest -for -pass
@JohnL4
JohnL4 / new-random-number.ps1
Created June 9, 2017 17:37
PowerShell snippet to quickly gin up a new random number.
(new-object Random).Next()
# Or...
$n = 9999999999
[Math]::Floor((new-object Random).NextDouble() * $n) + 1
@JohnL4
JohnL4 / whatis.ps1
Created April 24, 2017 17:43
What is that Windows process?
ps officeclicktorun | sel Description,path | ft -au -wr
@JohnL4
JohnL4 / Get-WindowsServicesAndTasksWithHardcodedPasswords.ps1
Last active August 23, 2022 18:05
PowerShell command to find logon account of Windows services; also cmd line to dump attributes of scheduled tasks to CSV file
<#
This might help in finding that pesky windows service that's always locking you out when you change your password and reboot.
#>
# ft is Format-Table; -auto is auto column width; -wrap is wrap text if necessary
Get-WmiObject win32_service | sort startname,startmode,state,displayname | select StartMode,State,StartName,DisplayName | ft -auto -wrap
# Or you can select only certain services.
# '?' is 'where' alias; -match uses regular expressions; -not is (obviously) a 'not' operator.
Get-WmiObject win32_service | ? {-not ($_.state -match 'running')} | sort startname,displayname | select StartMode,State,StartName,DisplayName | ft -auto -wrap