0
0
PowerShellscripting~10 mins

Why modules package reusable code in PowerShell - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import a module named 'MyModule'.

PowerShell
Import-Module [1]
Drag options to blanks, or click blank then click option'
ARemove-Module
BGet-Module
CNew-Module
DMyModule
Attempts:
3 left
💡 Hint
Common Mistakes
Using cmdlets like Get-Module instead of the module name.
Typing the wrong module name.
2fill in blank
medium

Complete the code to create a new module file named 'Utils.psm1'.

PowerShell
New-Item -Path . -Name [1] -ItemType File
Drag options to blanks, or click blank then click option'
AUtils.psm1
BUtils.ps1
CUtils.txt
DUtils.psd1
Attempts:
3 left
💡 Hint
Common Mistakes
Using .psd1 which is for module manifests.
Using .ps1 which is a script file, not a module.
3fill in blank
hard

Fix the error in the code to export a function named 'Get-Info' from a module.

PowerShell
Export-ModuleMember -Function [1]
Drag options to blanks, or click blank then click option'
Aget-info
BGet-Info
CGetInfo
DGet_Info
Attempts:
3 left
💡 Hint
Common Mistakes
Changing the function name format.
Using underscores instead of hyphens.
4fill in blank
hard

Fill both blanks to define a function named 'Show-Message' that writes 'Hello' to the console.

PowerShell
function [1] {
    [2] "Hello"
}
Drag options to blanks, or click blank then click option'
AShow-Message
BWrite-Host
CWrite-Output
DShowMessage
Attempts:
3 left
💡 Hint
Common Mistakes
Using Write-Output which sends output down the pipeline instead of directly to console.
Using function names without hyphens.
5fill in blank
hard

Fill all three blanks to create a module file that defines and exports a function 'Get-DateInfo' which returns the current date.

PowerShell
function [1] {
    return (Get-Date).[2]
}
Export-ModuleMember -Function [3]
Drag options to blanks, or click blank then click option'
AGet-DateInfo
BDate
DNow
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Now' instead of 'Date' property.
Mismatching function names in export.