ansible-collections / community.windows

Windows community collection for Ansible
https://galaxy.ansible.com/community/windows
GNU General Public License v3.0
193 stars 152 forks source link

[Fix] community.windows.win_psmodule_info throws exception when host has no Installed Module #532

Closed patware closed 10 months ago

patware commented 10 months ago

When a host has no installled Module, the $installedModules is null and $installedModules.Contains() throws an exception

SUMMARY

When the host does not have an installed module (in any version of PowerShell), the community.windows.win_psmodule_info throws a:

Unhandled exception while executing module: You cannot call a method on a null-valued expression.

With the -vvv, the details of the exception are:

The full traceback is:
You cannot call a method on a null-valued expression.
At line:294 char:5
+     Add-ModuleRepositoryInfo -RepositoryName $module.Params.repositor ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Add-ModuleRepositoryInfo], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull,Add-ModuleRepositoryInfo

ScriptStackTrace:
at Add-ModuleRepositoryInfo<Process>, <No file>: line 261
at <ScriptBlock>, <No file>: line 293

System.Management.Automation.RuntimeException: You cannot call a method on a null-valued expression.
ISSUE TYPE
COMPONENT NAME

module: community.windows.win_psmodule_info

jborean93 commented 10 months ago

Thanks!