5 ms·
Used PowerShell to code a small script and simply making md5 of a string is enough to make you feel nuts. The UNIX style. echo -n 'string' | md5 Compared t
by h1d 8y ago
Used PowerShell to code a small script and simply making md5 of a string is enough to make you feel nuts.
The UNIX style.
echo -n 'string' | md5
Compared to that obvious command, this is utter madness. You can't write a single thing without googling.
$string = "string"
$md5 = new-object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
$utf8 = new-object -TypeName System.Text.UTF8Encoding
$hash = [System.BitConverter]::ToString($md5.ComputeHash($utf8.GetBytes($string)))
$hash = $hash.ToLower() -replace '-', ''
No shit the Bash on Windows is a godsend.
- pjmlp 8y agoOf course, because someone wrote a md5 executable for you to call. You can do the same on PowerShell and write a pipeline just the same way.
- h1d 8y agoYou're right that a shell alone can't calculate md5 but a separate md5 binary does it for you, but the question still stands when the common answer on the internet seems to be to write that cryptic code as that's probably the easiest way provided on PowerShell. The best alternative I could find is some community maintained PowerShell extension (with just 177 GitHub stars now), which is far better but the lack of interest in making PowerShell act more straightforward is weird. "string" | Get-Hash -Algorithm MD5 (https://github.com/Pscx/Pscx https://github.com/Pscx/Pscx) Still feels funny to read the GGP's comment. > 70s-era tooling is inferior in some way to something designed with 30 years of hindsight
- TeMPOraL 8y agoStill, all that stops PS from being a better shell in linuxland is some people writing PS-equivalents of all the small executables that ship with your linux distribution.
- pjmlp 8y agoPowershell is based on the REPL ideas of Lisp Machines and Smalltalk. - structured data - ability to call any public function across dynamic libraries, COM objects and .NET frameworks - Powershell modules can also be called as plain .NET code Which UNIX shell provides this?
- oblio 8y agoThe easiest way is to launch md5sum from Powershell. It's a shell, at the end of the day...
- flukus 8y agoA while ago I was trying to copy a bunch of files and couldn't believe the powershell abominations I found: https://techblog.dorogin.com/powershell-how-to-recursively-copy-a-folder-structure-excluding-some-child-folders-and-files-a1de7e70f1b?gi=be511f23383a https://techblog.dorogin.com/powershell-how-to-recursively-c... $exclude = @("main.js") $excludeMatch = @("app") Get-ChildItem -Path $from -Recurse -Exclude $exclude | where { $excludeMatch -eq $null -or $_.FullName.Replace($from, "") -notmatch $excludeMatch } | Copy-Item -Destination { if ($_.PSIsContainer) { Join-Path $to $_.Parent.FullName.Substring($from.length) } else { Join-Path $to $_.FullName.Substring($from.length) } } -Force -Exclude $exclude All to do: find sourceFolder \! -path */app/* | xargs cp -t destFolder Screwed up the formatting a bit in the first example. I'm not positive the second works perfectly but I know which one I'd rather debug.
- h1d 8y agorsync -a --exclude=app/ --exclude=main.js sourceFolder/ destFolder/ Thank you, thank you unix tools.
- AnIdiotOnTheNet 8y agoFirst of all, the two examples you present do not do the same thing. The Powershell version preserves paths and excludes more patterns than your find | xargs example. The right way to do this is to just use robocopy. This example has targeted a very specific deficiency in the way Copy-Item works. I could similarly point out that the following Powershell command would be much more difficult in standard unix tooling: Get-WMIObject -Computer $remote -Class Win32_Product | Where-Object { $_.name -like "7-Zip*" } | select Version Which gets the version(s) of 7-Zip installed on a remote machine.