Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'OperatingSystem' is implicitly aliasing 'Get-OperatingSystem' #1907

Open
kieranwalsh opened this issue Apr 6, 2023 · 2 comments
Open

'OperatingSystem' is implicitly aliasing 'Get-OperatingSystem' #1907

kieranwalsh opened this issue Apr 6, 2023 · 2 comments

Comments

@kieranwalsh
Copy link

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?

@bergmeister
Copy link
Collaborator

Hmm, this seems to be a false positive, however I cannot reproduce it, even if I define a Get-OperatingSystem function or replace OperatingSystem with a Get- that I have on my system like ChildItem

@kieranwalsh
Copy link
Author

This still happens, but for others out there, the simple workaround it:

$Date = (get-date).AddDays(-14)
Get-ADComputer -Properties OperatingSystem, LastLogonTimeStamp -Filter {'OperatingSystem' -like '*Windows*' -and 'LastLogonTimeStamp' -gt $Date}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants