I am a little perplexed by this, i've been using VS Code for Writing PowerShell for over a year and had no issues until recently when it has started to reject fairly standard cmdlets as unknown.
Today I was trying to use Get-Eventlog
Get-EventLog -logname security -instanceid 4624
but I keep getting this error:
Get-EventLog: The term 'Get-EventLog' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again
According to MS Docs Get-EventLog is part of the Microsoft.PowerShell.Management module so I checked to see if it is loaded
get-module
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Manifest 7.0.0.0 Microsoft.PowerShell.Management {Add-Content, Clear-Content, Clear-Item, Clear-It…
Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Content, Clear-Content, Clear-Item, Clear-It…
Manifest 7.0.0.0 Microsoft.PowerShell.Security {ConvertFrom-SecureString, ConvertTo-SecureString…
Manifest 7.0.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Ob…
Script 0.2.0 PowerShellEditorServices.Commands {Clear-Host, ConvertFrom-ScriptExtent, ConvertTo-…
Binary 0.2.0 PowerShellEditorServices.VSCode {Close-VSCodeHtmlContentView, New-VSCodeHtmlConte…
Script 2.1.0 PSReadLine {Get-PSReadLineKeyHandler, Get-PSReadLineOption, …
It appears to be in the V3.1.0.0 version
get-command get-* | where source -eq Microsoft.PowerShell.Management
CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Get-ChildItem 7.0.0.0 Microsoft.PowerShell.Management
Cmdlet Get-Clipboard 7.0.0.0 Microsoft.PowerShell.Management
Cmdlet Get-ComputerInfo 7.0.0.0 Microsoft.PowerShell.Management
Cmdlet Get-ComputerRestorePoint 3.1.0.0 Microsoft.PowerShell.Management
Cmdlet Get-Content 7.0.0.0 Microsoft.PowerShell.Management
Cmdlet Get-ControlPanelItem 3.1.0.0 Microsoft.PowerShell.Management
Cmdlet Get-EventLog 3.1.0.0 Microsoft.PowerShell.Management
Cmdlet Get-HotFix 7.0.0.0 Microsoft.PowerShell.Management
Cmdlet Get-Item 7.0.0.0 Microsoft.PowerShell.Management
Cmdlet Get-ItemProperty 7.0.0.0 Microsoft.PowerShell.Management
Cmdlet Get-ItemPropertyValue 7.0.0.0 Microsoft.PowerShell.Management
Cmdlet Get-Location 7.0.0.0 Microsoft.PowerShell.Management
Cmdlet Get-Process 7.0.0.0 Microsoft.PowerShell.Management
Cmdlet Get-PSDrive 7.0.0.0 Microsoft.PowerShell.Management
Cmdlet Get-PSProvider 7.0.0.0 Microsoft.PowerShell.Management
Cmdlet Get-Service 7.0.0.0 Microsoft.PowerShell.Management
Cmdlet Get-TimeZone 7.0.0.0 Microsoft.PowerShell.Management
Cmdlet Get-Transaction 3.1.0.0 Microsoft.PowerShell.Management
Cmdlet Get-WmiObject 3.1.0.0 Microsoft.PowerShell.Management
but is absolutely not recognised in the (same) VSCode terminal window
get-command get-eventlog
Get-Command: The term 'get-eventlog' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
I removed the Microsoft.PowerShell.Management module
remove-module Microsoft.PowerShell.Management
confirmed that it had gone
get-module
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Manifest 7.0.0.0 Microsoft.PowerShell.Security {ConvertFrom-SecureString, ConvertTo-SecureString…
Manifest 7.0.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Ob…
Script 0.2.0 PowerShellEditorServices.Commands {Clear-Host, ConvertFrom-ScriptExtent, ConvertTo-…
Binary 0.2.0 PowerShellEditorServices.VSCode {Close-VSCodeHtmlContentView, New-VSCodeHtmlConte…
Script 2.1.0 PSReadLine {Get-PSReadLineKeyHandler, Get-PSReadLineOption, …
and then tried again
get-eventlog
get-eventlog: The term 'get-eventlog' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
The module was reloaded but the cmdlet isn't seen...
get-module
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Content, Clear-Content, Clear-Item, Clear-It…
Manifest 7.0.0.0 Microsoft.PowerShell.Security {ConvertFrom-SecureString, ConvertTo-SecureString…
Manifest 7.0.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Ob…
Script 0.2.0 PowerShellEditorServices.Commands {Clear-Host, ConvertFrom-ScriptExtent, ConvertTo-…
Binary 0.2.0 PowerShellEditorServices.VSCode {Close-VSCodeHtmlContentView, New-VSCodeHtmlConte…
Script 2.1.0 PSReadLine {Get-PSReadLineKeyHandler, Get-PSReadLineOption, …
$env:PSModulePath
contains the following paths
C:\Users\<username>\Documents\PowerShell\Modules;
C:\Program Files\PowerShell\Modules;
c:\program files\powershell\7\Modules;
C:\Program Files\WindowsPowerShell\Modules;
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules;
C:\Program Files\SharePoint Online Management Shell\;
C:\Program Files\Common Files\Skype for Business Online\Modules\;
c:\Users\<username>\.vscode\extensions\ms-vscode.powershell-2021.6.2\modules
I am very confused - any suggestions anybody?