function Install-ActiveDirectoryModule { <# .SYNOPSIS Installs the ActiveDirectory module by Enabling the WindowsFeature RSAT-AD-PowerShell #> [CmdletBinding()] [OutputType([bool])] param ( ) ## TODO: Anyone ~ Make this work on client operating systems, which relies on a hotfix installation and Enable-WindowsOptionalFeature ## dism /online /add-capability /capabilityname:Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0 $logLead = Get-LogLeadName # Try to load the module Import-Module ActiveDirectory -ErrorAction SilentlyContinue -Verbose:$false if (($null -ne $error[0]) -and ($null -ne $error[0].Exception) -and ($error[0].Exception.Message.StartsWith("The specified module 'ActiveDirectory'"))) { Write-Output "$logLead : The active directory module is not installed. Attempting to install it..." $result = Add-WindowsFeature RSAT-AD-PowerShell -Verbose:$false if ($result.ExitCode -ne "Success") { Write-Warning "$logLead : Installation of the RSAT module failed." return $false } else { Write-Output "$logLead : RSAT Module Installed Successfully. Loading it to host" Import-Module ActiveDirectory } } return $true }