Bird
0
0

You want to check if the AD module is installed and import it only if present. Which script snippet is correct?

hard📝 Application Q9 of 15
PowerShell - Active Directory
You want to check if the AD module is installed and import it only if present. Which script snippet is correct?
AImport-Module ActiveDirectory -ErrorAction SilentlyContinue
Bif (Get-Module -ListAvailable -Name ActiveDirectory) { Import-Module ActiveDirectory }
CGet-WindowsFeature RSAT-AD-PowerShell | Import-Module
DAdd-WindowsCapability -Online -Name Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0
Step-by-Step Solution
Solution:
  1. Step 1: Check module availability

    Get-Module -ListAvailable checks if the module is installed on the system.
  2. Step 2: Import module conditionally

    If the module is found, Import-Module loads it into the session.
  3. Step 3: Verify other options

    Import-Module ActiveDirectory -ErrorAction SilentlyContinue imports without checking; C is invalid syntax; D installs module but does not check.
  4. Final Answer:

    if (Get-Module -ListAvailable -Name ActiveDirectory) { Import-Module ActiveDirectory } -> Option B
  5. Quick Check:

    Check then import module = if (Get-Module -ListAvailable -Name ActiveDirectory) { Import-Module ActiveDirectory } [OK]
Quick Trick: Use Get-Module -ListAvailable to check before importing [OK]
Common Mistakes:
  • Importing without checking causes errors
  • Using invalid pipeline commands
  • Confusing install commands with import

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes