From 421d9540dae0335668d6cca774228dc0f1f17bcc Mon Sep 17 00:00:00 2001 From: Sylvain Audie Date: Mon, 25 Sep 2023 10:44:26 +0200 Subject: [PATCH] feat(object_info): add activedirectory module import --- .../fragments/73-import-activedirectory-module.yml | 2 ++ plugins/modules/object_info.ps1 | 12 +++++++++++- plugins/modules/object_info.py | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/73-import-activedirectory-module.yml diff --git a/changelogs/fragments/73-import-activedirectory-module.yml b/changelogs/fragments/73-import-activedirectory-module.yml new file mode 100644 index 0000000..e320d5f --- /dev/null +++ b/changelogs/fragments/73-import-activedirectory-module.yml @@ -0,0 +1,2 @@ +minor_changes: +- object_info - Add ActiveDirectory module import \ No newline at end of file diff --git a/plugins/modules/object_info.ps1 b/plugins/modules/object_info.ps1 index d386417..4e304fe 100644 --- a/plugins/modules/object_info.ps1 +++ b/plugins/modules/object_info.ps1 @@ -46,6 +46,14 @@ $properties = $module.Params.properties $searchBase = $module.Params.search_base $searchScope = $module.Params.search_scope +# Attempt import of ActiveDirectory module +try { + Import-Module -Name ActiveDirectory +} +catch { + $module.FailJson("The ActiveDirectory module failed to load properly: $($_.Exception.Message)", $_) +} + $credential = $null if ($domainUsername) { $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @( @@ -223,7 +231,9 @@ try { # We run this in a custom PowerShell pipeline so that users of this module can't use any of the variables defined # above in their filter. While the cmdlet won't execute sub expressions we don't want anyone implicitly relying on # a defined variable in this module in case we ever change the name or remove it. - $ps = [PowerShell]::Create() + $iss = [InitialSessionState]::CreateDefault() + $iss.ImportPSModule("ActiveDirectory") + $ps = [PowerShell]::Create($iss) $null = $ps.AddCommand('Get-ADObject').AddParameters($commonParams).AddParameters($getParams) $null = $ps.AddCommand('Select-Object').AddParameter('Property', @('DistinguishedName', 'ObjectGUID')) diff --git a/plugins/modules/object_info.py b/plugins/modules/object_info.py index 0fe2f54..146fa30 100644 --- a/plugins/modules/object_info.py +++ b/plugins/modules/object_info.py @@ -88,6 +88,7 @@ and C(userAccountControl_AnsibleFlags) return property is something set by the module itself as an easy way to view what those flags represent. These properties cannot be used as part of the I(filter) or I(ldap_filter) and are automatically added if those properties were requested. +- This must be run on a host that has the ActiveDirectory powershell module installed. extends_documentation_fragment: - ansible.builtin.action_common_attributes attributes: