0
0
PowerShellscripting~20 mins

Module creation basics 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 importing a module with a function?
You have a PowerShell module file named MyTools.psm1 containing this function:
function Get-Greeting { "Hello, World!" }

After running Import-Module .\MyTools.psm1 and then Get-Greeting, what is the output?
PowerShell
function Get-Greeting { "Hello, World!" }

Import-Module .\MyTools.psm1
Get-Greeting
AHello, World!
BGet-Greeting
CError: Command not found
DModule imported successfully, no output
Attempts:
2 left
💡 Hint
Think about what the function returns when called after importing the module.
📝 Syntax
intermediate
2:00remaining
Which option correctly defines a PowerShell module manifest?
You want to create a module manifest file MyTools.psd1 for your module. Which snippet correctly starts the manifest with the required syntax?
A
{
    ModuleVersion = '1.0'
    GUID = '12345678-1234-1234-1234-123456789abc'
}
B
@{
    ModuleVersion = '1.0'
    GUID = '12345678-1234-1234-1234-123456789abc'
}
C
[Hashtable]
ModuleVersion = '1.0'
GUID = '12345678-1234-1234-1234-123456789abc'
D
<#
ModuleVersion = '1.0'
GUID = '12345678-1234-1234-1234-123456789abc'
#>
Attempts:
2 left
💡 Hint
A module manifest is a PowerShell hashtable saved in a .psd1 file.
🔧 Debug
advanced
2:00remaining
Why does this module function fail to export?
You have a module file MyTools.psm1 with this content:
function Get-Secret { "Top Secret" }
Export-ModuleMember -Function Get-Secret

After importing the module, running Get-Secret gives an error: Get-Secret : The term 'Get-Secret' is not recognized. Why?
PowerShell
function Get-Secret { "Top Secret" }
Export-ModuleMember -Function Get-Secret
AThe module file must be saved with a .psd1 extension to export functions
BExport-ModuleMember must be called before defining the function
CThe function is not exported because Export-ModuleMember is missing the -Function parameter value in quotes
DThe function name is case-sensitive and should be 'get-secret' in Export-ModuleMember
Attempts:
2 left
💡 Hint
Check how the function name is passed to Export-ModuleMember.
🚀 Application
advanced
2:00remaining
How to automatically import a module when a function is called?
You want to create a module that loads only when its function is called, to save memory. Which method achieves this in PowerShell?
AUse <code>AutoLoading</code> feature by placing the module in a standard module path
BUse <code>ModuleToProcess</code> in the module manifest to specify the .psm1 file
CUse <code>Import-Module</code> inside the function definition
DUse <code>Export-ModuleMember</code> with the <code>-AutoImport</code> flag
Attempts:
2 left
💡 Hint
PowerShell can auto-load modules placed in specific folders.
🧠 Conceptual
expert
2:00remaining
What is the main purpose of a PowerShell module manifest?
Choose the best description of what a module manifest (.psd1) file does in PowerShell module creation.
AIt contains the actual function code and scripts to run
BIt automatically imports the module when PowerShell starts
CIt compiles the module into a binary executable
DIt defines metadata, dependencies, and exported commands for the module
Attempts:
2 left
💡 Hint
Think about what information helps PowerShell manage the module.