Chameleon (sometimes penguin or dog) furry artist and shitposter. Like airplanes, chemicals, theme parks, music, Yu-Gi-Oh, baking, and baths but isn't good at any of those. Super busy at work all the time.

More active on FA or Fediverse

Posts may contain strong language or mature references. VIOWER EXCRETION ADVISD.

Icon by https://www.furaffinity.net/user/klaora
Header image by https://www.furaffinity.net/user/charmersshelter/

posts from @Miff tagged #powershell

also:

gitPowerShell
git configSet-GitConfguration
git initInitialize-GitRepository
git cloneCopy-GitRepository
git addAdd-GitFile
git statusGet-GitStatus
git diffCompare-GitChanges
git commitSave-GitChanges
git restoreRestore-GitFile
git resetUndo-GitChanges
git rmRemove-GetFile
git mvMove-GitFile
git branchShow-GitBranches
git branch (name)Add-GitBranch
git branch -dRemove-GitBranch
git checkoutSwitch-GitBranch
git mergeMerge-GitBranch
git logShow-GitLog
git stashCheckpoint-GitStash
git stash listShow-GitStashes
git stash popRestore-GitStash
git stash dropRemove-GitStash
git tagShow-GitTags
git tag (name)Add-GitTag
git pullReceive-GitRemote
git pushSend-GitRemote
git remoteGet-GitRemotes
git remote addConnect-GitRemote
git showGet-GitCommit
git revertRestore-GitCommit
git rebaseRestore-Gitcommit -Rebase


I know that programmers have overwhemlingly rejected PowerShell but I legit like it.

Douglas McIlroy famously said that UNIX programs should interoperate with text streams becasue that is a universal interface. Text streams have their problems, though. There's no way to delinaiate arbitrary data, because any seperators can also themslves be data. A traditional UNIX pipeline uses string matching to filter data (which could create false positives if it picks something up from another field) and a complete programming language for selecting fields.

However, this isn't the 1970s anymore, and we have a much better universal interface: Objects.

JSON is the industry standard format for information storage and interchange and it expreses data as objects- associvate arrays that clearly separate structure and content and provide context to every field. Nearly every programming language can read it which means that nearly every programming language has a concept of objects.

PowerShell's big innovation is that it pipes objects.

Here, I'll give a quick example one-liner. This will get a list of processes (Names and IDs) using more than 100 MB of RAM ordered by the amount of ram using (largest to smallest).

ps | where { $_.WS -gt 1024*1024*100 } | sort -d WS | select ProcessName,ID

And look at the output of this

ProcessName                 Id
-----------                 --
svchost                   7744
Telegram                 10948
Dropbox                  16992
msedge                   20856
MsMpEng                   4880
vcxsrv                   13612
Discord                  16440
explorer                  9416
(Output clipped for brevity)

By Jove! Headers! UNIX programs like ls and ps lose their header informatino as soon as they get passed into grep (which they probably should because otehrwise the headers will be treated as data further down the line). Meanwhile, the strongly-named object information made its way all the way down the pipeline. If I wanted to, I could pipe this into ConvertTo-Json and then I'd have this as JSON that could be fed into any external application. I could also turn it into CSV or some overly complex XML.

Also, note that that one one liner above doesn't use any cmdlet-style names. Nearly every common command has a permanent alias, and those aliases are often the equivalent UNIX tools. I can ls instead of Get-ChildObject, cp instead of Copy-Item, cat instead of Get-Content, and in this case, ps instead of Get-Process.

where and select are just the same filter and map functions you'll find in most higher level languages. The names aren't PowerShell arbitrariness, Where and Select are the names of C#'s filter and map functions, and they take their names from SQL.

Another note: The parameter I passed to where wasn't a regex or obtuse bit of code in a completly different language. It wasn't just PowerShell code it was a lambda. I pretty much said x => x.WS > 1024*1024*100.

And it was just as much of an object as a JavaScript function as well. I can assign it to a variable and use that variable as a parameter.

$workingSetFilter = { $_.WS -gt 1024*1024*100 } ; ps | where $workingSetFilter

The -gt is a bit of odd syntax, but like the names where and select, this syntax is also taken from an established language: UNIX shell scripts.

Also, note above that I only had to write a lambda for the where function and that sort and select just infered what value I wanted by the name alone.

While powershell may have a learning curve for the syntax and its own WTF moments like function parameters, it's not without its merits.

PowerShell isn't a solution looking for a problem. It's a reimagining of what a shell could be and one day could beget something that people actually love like how Swift begat Kotlin.

(And in the long run, I pretty much just use for the same basic command line file management and command-line program invocation that one would use with a UNIX shell (or even cmd). ls, cd, and git all work the same across PS and UNIX.)

Thank you for coming to my TED talk. All hate/death threats received for this post may be archived and published. :)