pwsh -NoProfile -Command {
Get-Command -Noun 'ItemProperty*' -PipelineVariable 'command' |
ForEach-Object {
$alias = Get-Alias -Definition $_.Name -ErrorAction Ignore
if ($alias) {
$alias
} else {
$null
}
} -PipelineVariable 'alias' |
ForEach-Object {
[PSCustomObject] @{
Command = $command.Name
Alias = $alias.Name
Options = $alias.Options
}
}
}
Command Alias Options
------- ----- -------
Clear-ItemProperty clp ReadOnly
Copy-ItemProperty cpp ReadOnly
Get-ItemProperty gp ReadOnly
Get-ItemPropertyValue gpv ReadOnly
Move-ItemProperty mp ReadOnly
New-ItemProperty np ReadOnly
Remove-ItemProperty rp ReadOnly
Rename-ItemProperty rnp ReadOnly
Set-ItemProperty sp ReadOnly
Command Alias Options
------- ----- -------
Clear-ItemProperty clp ReadOnly
Copy-ItemProperty cpp ReadOnly
Get-ItemProperty gp ReadOnly
Get-ItemPropertyValue gpv ReadOnly
Move-ItemProperty mp ReadOnly
New-ItemProperty
Remove-ItemProperty rp ReadOnly
Rename-ItemProperty rnp ReadOnly
Set-ItemProperty sp ReadOnly
Name Value
---- -----
PSVersion 6.2.1
PSEdition Core
GitCommitId 6.2.1
OS Microsoft Windows 10.0.17763
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0, 5.0, 5.1.10032.0, 6.2.1}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
@travislagrone Reading between the lines, you appear to be asserting that we should add 'np' as an alias for New-ItemProperty - correct? Now aliases are for interactive use, in theory to act as accelerators to facillitate interactive operations. In practise I suspect that in fact New-ItemProperty is not used enough to warrant acceleration (please tell me if i am wrong.) so there's not much justification to do this. Also, it would be a breaking change since it adding it would hid existing "np" commands. Thoughts?
@BrucePay From my perspective, _none_ of the *-ItemProperty cmdlets are used enough by enough people to warrant a built-in pre-defined alias. If I had my preference, I'd remove all of their aliases from "language-native" status.
That being said, if PowerShell is choosing to / has already _de facto_ committed to aliasing the *-ItemProperty cmdlets, then it should provide consistency in that regard. Otherwise, the implicit expectation of "ItemProperty cmdlet aliases are a language-native feature" that is built up by the presence of literally all of them except one is violated in a somewhat jarring (albeit minor) way when encountered during interactive work.
All that being said, this issue appears to me more like an accidental oversight given the intention to alias them all, rather than a mediated decision that New-ItemProperty in particular is fundamentally less deserving of an alias then every other *-ItemProperty cmdlet (whatever "deserving" was defined as by the original creator(s)).
Am I characterizing the genesis of this inconsistency fairly? And either way, is it actually feasible to "demote" (so to speak) the *-ItemProperty cmdlet aliases from "language-native" status?
I agree that they are not widely used, but removing them will break things. So that's a bad thing.
Adding that alias would improve consistency. So that would be a plus.
Somewhat random comments: Aliases are an interactive-convenience feature rather than a "language-native feature" and, for the most part, should not be used in production scripts. I don't remember us making a conscious decision to exclude New-ItemProperty (@khansen00 might remember more) so it's probably an oversight. However even though you shouldn't use aliases in scripts, people do so removing the existing aliases would be a breaking change. Adding a new alias would also be a breaking change because people might have their own "np" command. Yes we were overly enthusiastic adding aliases in the beginning. Clearly not everything needs an alias but it was our "defence against verbosity" argument. The core scenario for the ItemProperty commands is the registry which has both items and values (properties).
@BrucePay I think I might have come across as a bit abrasive in my initial response. If so, I apologize. It was not my intention.
If it helps to clarify my position, I agree with you that aliases should be considered a "convenience feature" for interactive work, and that they should not be used in production scripts.
So, to advance the discussion, do you--or anyone else on the PowerShell team--know of any good way to search a corpus of PowerShell files with regex? In particular, I would like to perform a survey of public PowerShell scripts on GitHub for the incidence of the ItemProperty cmdlet aliases, as well as that of my proposed "np" alias.
@travisclagrone
as well as that of my proposed "np" alias.
The problem with that is that a large portion of the folks who would use that in a script, aren't typically the type of folks to publish their work.
That said, I would be much more worried about breaking profiles. Personally I don't like the idea of any additional two letter command names being reserved, regardless of the command's popularity.
For reference https://github.com/PowerShell/PowerShell-RFC/pull/129 - long story about aliases.
@travisclagrone I did a quick search of github using:
language:powershell "gp -path"
This returned a few hits (ones that aren't part of our test suites) so the aliases are definitely used though not frequently. As @SeeminglyScience points out, most uses are likely in casual files or profiles.
On the other hand, proving that it's safe to add an alias like 'np' i.e. that it _isn't_ currently used is impossible. The best you say that it isn't used in the body of software you checked. That said, I did a search
language:powershell " np -path"
and there is one hit where np is used as a command.
Given the discussion and results so far, I believe it is appropriate to close this issue. At the very least, it can now stand as documentation + commentary for posterity.
Most helpful comment
@travisclagrone I did a quick search of github using:
This returned a few hits (ones that aren't part of our test suites) so the aliases are definitely used though not frequently. As @SeeminglyScience points out, most uses are likely in casual files or profiles.
On the other hand, proving that it's safe to add an alias like 'np' i.e. that it _isn't_ currently used is impossible. The best you say that it isn't used in the body of software you checked. That said, I did a search
and there is one hit where
npis used as a command.