Concept Flow - AD module installation
Start
Check if AD module is installed
Import
Import AD module
End
The script checks if the Active Directory module is installed. If not, it installs it, then imports the module for use.
Jump into concepts and practice - no test required
if (-not (Get-Module -ListAvailable -Name ActiveDirectory)) {
Install-WindowsFeature -Name RSAT-AD-PowerShell
}
Import-Module ActiveDirectory
Get-Module ActiveDirectory| Step | Action | Evaluation | Result |
|---|---|---|---|
| 1 | Check if AD module is available | Get-Module -ListAvailable -Name ActiveDirectory | False (module not found) |
| 2 | Install AD module | Install-WindowsFeature -Name RSAT-AD-PowerShell | Success (module installed) |
| 3 | Import AD module | Import-Module ActiveDirectory | Module imported |
| 4 | Verify import | Get-Module ActiveDirectory | ActiveDirectory module listed |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 | Final |
|---|---|---|---|---|---|
| ADModuleAvailable | null | False | False | True | True |
Check if AD module exists with Get-Module -ListAvailable. If missing, install with Install-WindowsFeature RSAT-AD-PowerShell. Import module using Import-Module ActiveDirectory. Verify import with Get-Module ActiveDirectory. This ensures AD cmdlets are ready to use.
Import-Module ActiveDirectory -ErrorAction SilentlyContinue; Get-Module ActiveDirectory
Import-Module ActiveDirectory but get an error saying the module is not found. What is the most likely fix?