Skip to content

Commit

Permalink
feat(object_info): add activedirectory module import (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
gotit96 authored Sep 25, 2023
1 parent bea087f commit 6a577ee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/73-import-activedirectory-module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- object_info - Add ActiveDirectory module import
12 changes: 11 additions & 1 deletion plugins/modules/object_info.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 @(
Expand Down Expand Up @@ -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'))

Expand Down
1 change: 1 addition & 0 deletions plugins/modules/object_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 6a577ee

Please sign in to comment.