0
0
PowerShellscripting~20 mins

Importing modules in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 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.