PowerShell / PowerShell/PSScriptAnalyzer
'OperatingSystem' is implicitly aliasing 'Get-OperatingSystem'
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2.2k
- Forks
- 414
- Avg merge
- 13h 1m
- Merged PRs (30d)
- 2
Description
I keep getting warnings about implicitly aliasing which I feel are incorrect, but perhaps I'm missing something from my code.
Steps to reproduce
$Date = (get-date).AddDays(-14)
Get-ADComputer -Properties OperatingSystem, LastLogonTimeStamp -Filter {OperatingSystem -like '*Windows*' -and LastLogonTimeStamp -gt $Date}
Expected behavior
I should get a list of Windows computers with recent logons
Actual behavior
VSCode warns me that:
'OperatingSystem' is implicitly aliasing 'Get-OperatingSystem' because it is missing the 'Get-' prefix. This can introduce possible problems and make scripts hard to maintain. Please consider changing command to its full name.
The auto-formatting then changes my code so my code fails.
Environment data
$PSVersionTable
Name Value
---- -----
PSVersion 5.1.19041.2673
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.2673
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
VSCode 1.76.2
PSScriptAnalyzer 1.21.0
PowerShell extension v2023.3.3
Windows 10 Enterprise Version 22H2
OS Build 19045.2728
Outside of adding the data to the whitelist, should I be writing my code differently to avoid this issue?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied PowerShell reproducer in issue 1907 and compare the warning and formatting behavior reported with PSScriptAnalyzer 1.21.0 in VS Code. Trace the implicit-alias diagnostic and formatter path; done means the AD property OperatingSystem no longer produces a false warning or destructive rewrite, with regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100