Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(object_info): add activedirectory module import #73

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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