jdhitsolutions / PSTeachingTools

:mortar_board: A set of commands and tools for teaching PowerShell. The module should work in Windows PowerShell, PowerShell 7.x and run cross-platform.
MIT License
48 stars 22 forks source link

Get-, Set-, New-Vegetable commands are not working #8

Closed andrasfeher closed 3 years ago

andrasfeher commented 3 years ago

The module was installed fine:

Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
......
Script     3.2.1      PSTeachingTools                     {Get-Vegetable, New-Vegetable, Set

PS SQLSERVER:\> get-command -noun vegetable

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Function        Get-Vegetable                                      3.2.1      PSTeachingTools
Function        New-Vegetable                                      3.2.1      PSTeachingTools
Function        Set-Vegetable                                      3.2.1      PSTeachingTool

But any other operation gives me errors:

PS SQLSERVER:\> Get-Vegetable | Get-Member
WARNING: Failed to find vegetable source.
Get-Member : You must specify an object for the Get-Member cmdlet.
At line:1 char:17
+ Get-Vegetable | Get-Member
+                 ~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-Member], InvalidOperationException
    + FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand

PS SQLSERVER:\> help New-Vegetable
Get-Help : Unable to find type [vegcolor].
At line:55 char:5
+     Get-Help @PSBoundParameters | more
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (vegcolor:TypeName) [Get-Help], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.GetHelpCommand

PS SQLSERVER:\> help Set-Vegetable
Get-Help : Unable to find type [Vegetable].
At line:55 char:5
+     Get-Help @PSBoundParameters | more
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Vegetable:TypeName) [Get-Help], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.GetHelpCommand
jdhitsolutions commented 3 years ago

That is very odd. I'm assuming a command like Get-Service | Get-Member works fine? What version of PowerShell are you running? Try importing the module first, import-module psteachingtools -force and then running commands. The module does some prep when you install it. I've seen situations where if you just run the command like Get-Vegetable not everything gets loaded that should be.

andrasfeher commented 3 years ago

I restarted my machine, and thus PowerShell, in the meantime and now everything works fine without importing the module.

The old reboot trick worked again.

I also tried to reproduce the error on basis of the transcript that I made, but it now it works correctly.

Thanks and best regards, Andras