Bird
Raised Fist0
PowerShellscripting~20 mins

Importing modules in PowerShell - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
PowerShell Module Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this PowerShell command?
Consider the following command to import a module and list its commands:

Import-Module Microsoft.PowerShell.Utility; Get-Command -Module Microsoft.PowerShell.Utility | Select-Object -First 3 -ExpandProperty Name

What will this command output?
PowerShell
Import-Module Microsoft.PowerShell.Utility; Get-Command -Module Microsoft.PowerShell.Utility | Select-Object -First 3 -ExpandProperty Name
A
Add-History
Add-Member
Compare-Object
B
Get-Process
Get-Service
Start-Process
C
Import-Module
Get-Command
Select-Object
D
New-Item
Remove-Item
Copy-Item
Attempts:
2 left
💡 Hint
Think about common commands in the Utility module.
📝 Syntax
intermediate
2:00remaining
Which option correctly imports a module only if it is not already imported?
You want to import the module 'Az.Accounts' only if it is not already loaded in the current session. Which of the following PowerShell snippets does this correctly?
AImport-Module Az.Accounts -Force
Bif (-not (Get-Module -Name Az.Accounts)) { Import-Module Az.Accounts }
CGet-Module Az.Accounts | Import-Module
DImport-Module -Name Az.Accounts -SkipIfLoaded
Attempts:
2 left
💡 Hint
Check how to test if a module is loaded before importing.
🔧 Debug
advanced
2:00remaining
Why does this import command fail with an error?
You run this command:

Import-Module -Name NonExistentModule

and get the error:

Import-Module : The specified module 'NonExistentModule' was not loaded because no valid module file was found in any module directory.

What is the most likely reason?
AThe module 'NonExistentModule' is not installed or not in any module path.
BThe module name is misspelled but the module is installed.
CThe command requires administrator privileges to import any module.
DPowerShell does not support importing modules with the -Name parameter.
Attempts:
2 left
💡 Hint
Check if the module exists on your system.
🚀 Application
advanced
2:00remaining
How to import a module from a specific path?
You have a PowerShell module located at 'C:\CustomModules\MyModule'. Which command correctly imports this module from that path?
AImport-Module -Name C:\CustomModules\MyModule\MyModule.psm1
BImport-Module -ModulePath C:\CustomModules\MyModule
CImport-Module -Path C:\CustomModules\MyModule\MyModule.psm1
DImport-Module -Source C:\CustomModules\MyModule
Attempts:
2 left
💡 Hint
Use the parameter that specifies the module file path.
🧠 Conceptual
expert
2:00remaining
What happens when you import a module with the -Scope Global parameter?
In PowerShell, what is the effect of importing a module using the -Scope Global parameter like this?

Import-Module MyModule -Scope Global

Choose the correct explanation.
AThe module is imported only for the current script and not available in the interactive session.
BThe module is imported but only for the current user, not system-wide.
CThe module is imported with elevated privileges, requiring administrator rights.
DThe module is imported into the global session state, making its commands available to all child scopes and scripts.
Attempts:
2 left
💡 Hint
Think about scope and session states in PowerShell.

Practice

(1/5)
1. What does the Import-Module command do in PowerShell?
easy
A. Loads a module so you can use its commands in the current session
B. Deletes a module from your computer
C. Creates a new module file
D. Lists all installed modules on your system

Solution

  1. Step 1: Understand the purpose of Import-Module

    The Import-Module command is used to load a module into the current PowerShell session so its commands become available.
  2. Step 2: Compare options with the command's function

    Only Loads a module so you can use its commands in the current session correctly describes loading a module for use. Other options describe unrelated actions.
  3. Final Answer:

    Loads a module so you can use its commands in the current session -> Option A
  4. Quick Check:

    Import-Module loads commands [OK]
Hint: Import-Module means load commands to use now [OK]
Common Mistakes:
  • Thinking Import-Module deletes or creates modules
  • Confusing Import-Module with Get-Module
  • Assuming Import-Module lists modules
2. Which of the following is the correct syntax to import a module named MyTools in PowerShell?
easy
A. Import Module MyTools
B. ImportModule MyTools
C. Import-Module -Module MyTools
D. Import-Module MyTools

Solution

  1. Step 1: Recall the basic Import-Module syntax

    The simplest correct syntax is Import-Module ModuleName without extra parameters.
  2. Step 2: Check each option's syntax

    Import-Module MyTools matches the correct syntax exactly. The other options have syntax errors: space between Import and Module, invalid parameter -Module, and missing hyphen before Module.
  3. Final Answer:

    Import-Module MyTools -> Option D
  4. Quick Check:

    Use Import-Module followed by module name [OK]
Hint: Use Import-Module followed by module name [OK]
Common Mistakes:
  • Adding spaces in command name like 'Import Module'
  • Missing dash in Import-Module
  • Using wrong parameter names
3. What will be the output of this PowerShell code?
Import-Module Microsoft.PowerShell.Utility
Get-Command -Module Microsoft.PowerShell.Utility | Select-Object -First 1 -ExpandProperty Name
medium
A. Add-Type
B. Get-Process
C. Format-Table
D. Sort-Object

Solution

  1. Step 1: Understand the commands used

    The code imports the Utility module, then lists commands from it, selecting the first command's name.
  2. Step 2: Identify the first command in the Utility module

    The first command in Microsoft.PowerShell.Utility (in export order) is 'Add-Type'.
  3. Final Answer:

    Add-Type -> Option A
  4. Quick Check:

    First command in Utility module is Add-Type [OK]
Hint: First command in Utility module is Add-Type [OK]
Common Mistakes:
  • Assuming output is a command not in the module
  • Confusing command names with similar ones
  • Not expanding property to get name
4. You run Import-Module MyModule but get an error: ModuleNotFoundException. What is the most likely cause?
medium
A. You used the wrong command; it should be Load-Module
B. You forgot to run PowerShell as administrator
C. The module name is misspelled or not installed
D. The module is already imported

Solution

  1. Step 1: Understand the error meaning

    ModuleNotFoundException means PowerShell cannot find the module by that name.
  2. Step 2: Identify common causes

    The most common cause is a misspelled module name or the module is not installed on the system.
  3. Final Answer:

    The module name is misspelled or not installed -> Option C
  4. Quick Check:

    ModuleNotFound means module missing or misspelled [OK]
Hint: ModuleNotFound means module missing or name wrong [OK]
Common Mistakes:
  • Assuming admin rights always fix this error
  • Using wrong command name like Load-Module
  • Thinking module is imported already causes error
5. You want to import a module only if it is not already loaded in your PowerShell session. Which script snippet correctly does this?
hard
A. Import-Module MyModule -Force
B. if (-not (Get-Module -Name MyModule)) { Import-Module MyModule }
C. Get-Module MyModule | Import-Module
D. Import-Module MyModule -SkipIfLoaded

Solution

  1. Step 1: Understand how to check if a module is loaded

    Get-Module -Name MyModule returns the module if loaded, or nothing if not.
  2. Step 2: Use conditional to import only if not loaded

    The condition -not (Get-Module -Name MyModule) checks if module is missing, then imports it.
  3. Step 3: Evaluate other options

    Import-Module MyModule -Force forces import regardless. Piping Get-Module output to Import-Module is invalid syntax. -SkipIfLoaded is not a valid parameter.
  4. Final Answer:

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

    Check with Get-Module before Import-Module [OK]
Hint: Check Get-Module before Import-Module to avoid duplicates [OK]
Common Mistakes:
  • Using Import-Module -Force to avoid checking
  • Trying to pipe Get-Module output to Import-Module
  • Using non-existent parameters like -SkipIfLoaded
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard