3 ms·
Scripts should not use the aliases because they can differ across machines or users. The cmdlet names are stable. That being said, for quick one-off scripts my
by ygra 2y ago
Scripts should not use the aliases because they can differ across machines or users. The cmdlet names are stable. That being said, for quick one-off scripts my code looks very much like my command-line usage, which is somewhere between terse and golfed.
Idiomatic PowerShell embraces the pipeline, though. The number of scripts I've seen in the wood which were haphazardly ported from VBScript or C# showed, however, that people don't care about idiomatic.
- 13of40 2y agoBuilt-in aliases are guarateed to be present, so you can depend on them. There are other features, like shortened parameter names that might become ambiguous when new parameters are added, that aren't guaranteed backwards compatible, but aliases are stable.
- jasomill 2y agoNot necessarily: 1. UNIX-compatibility aliases like "ls -> Get-ChildItem" and "cat -> Get-Content" are not defined in PowerShell on Linux or macOS. For a complete list of these, see the PowerShell source code[1] (look for "#if !UNIX"). 2. A number of aliases from PowerShell ≤ 5.1 were removed in PowerShell Core (≥ 6.0), including the particularly annoying "curl -> Invoke-WebRequest" (conflicts with curl.exe) and "sc -> Set-Content" (conflicts with sc.exe). [1] https://github.com/PowerShell/PowerShell/blob/8ea1598964590b7551ffacda2d2007b94da1e5fa/src/System.Management.Automation/engine/InitialSessionState.cs#L4695 https://github.com/PowerShell/PowerShell/blob/8ea1598964590b...
- ygra 2y agoIn addition to the other comment, PowerShell loads a profile script where a user may freely remove aliases or redefine them as they see fit. It's also a reason why my command line for executing PowerShell scripts includes -noprofile.