PowerShell / PowerShell/PSScriptAnalyzer
'OperatingSystem' is implicitly aliasing 'Get-OperatingSystem'
還沒有人認領這個 Issue。
- 主要語言
- C#
- 星號
- 2.2k
- 分支
- 415
- 平均合併
- 13 小時 1 分鐘
- 30 天內合併 PR
- 2
描述
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?
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 issue 1907 中提供的 PowerShell 重現步驟開始,並將回報的警告與格式化行為和 VS Code 中的 PSScriptAnalyzer 1.21.0 進行比較。追蹤隱含別名診斷與 formatter 路徑;當 AD 屬性 OperatingSystem 不再產生錯誤警告或破壞性重寫,並具備回歸測試涵蓋時,即視為完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- powershell
- 領域
- tooling
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100