'Get-Command' returns a list of all available commands in a powershell session.
The following code evaluates to $false, when passed a string which is not a command:
function f($x) {[bool](Get-Command $x -ErrorAction SilentlyContinue)}
And it does:
PS C:\Windows\system32> f ls
True
PS C:\Windows\system32> f alkdsjfasd
False
So you would think that the following code would return the list of commands which are not commands -- that is an empty list:
Get-Command | Where-Object {[bool](Get-Command $_ -ErrorAction SilentlyContinue) -eq $false}
Except it doesn't. It returns the following on a clean Windows Server 2016 VM:
CommandType Name Version Source
----------- ---- ------- ------
Function Get-IseSnippet 1.0.0.0 ISE
Function Import-IseSnippet 1.0.0.0 ISE
Function New-IseSnippet 1.0.0.0 ISE
Function Start-AutologgerConfig 1.0.0.0 EventTracingManagement
Cmdlet Add-ClusteriSCSITargetServerRole 2.0.0.0 IscsiTarget
If I wait a little while and run the same command again, it returns a much longer list:
CommandType Name Version Source
----------- ---- ------- ------
Function Add-RDServer 2.0.0.0 RemoteDesktop
Function Add-RDSessionHost 2.0.0.0 RemoteDesktop
Function Add-RDVirtualDesktopToCollection 2.0.0.0 RemoteDesktop
Function Disable-RDVirtualDesktopADMachineAccountReuse 2.0.0.0 RemoteDesktop
Function Get-IseSnippet 1.0.0.0 ISE
...
Function Test-RDVirtualDesktopADMachineAccountReuse 2.0.0.0 RemoteDesktop
Function Update-RDVirtualDesktopCollection 2.0.0.0 RemoteDesktop
I've checked the files in the RemoteDesktop module, for example, and I've been able to find the functions that are "missing".
What is going on here? How can 'Get-Command' return "commands" that aren't commands?