What is a PowerShell module manifest (.psd1 file)?
A module manifest is a special file in PowerShell that describes the contents and settings of a module. It helps PowerShell know what files belong to the module, its version, author, and other important details.
Click to reveal answer
beginner
Which cmdlet is used to create a new module manifest in PowerShell?
The cmdlet <code>New-ModuleManifest</code> is used to create a new module manifest file (.psd1). It guides you to specify details like module version, author, and required modules.
Click to reveal answer
intermediate
Name three key properties you can define in a PowerShell module manifest.
Three key properties are:
ModuleVersion: The version number of the module.
Author: The creator of the module.
FunctionsToExport: The list of functions the module makes available to users.
Click to reveal answer
intermediate
Why should you use a module manifest instead of just a script file for your PowerShell module?
A module manifest helps organize your module by listing all parts, controlling what is visible to users, specifying dependencies, and providing metadata. This makes your module easier to maintain and share.
Click to reveal answer
advanced
What happens if you set FunctionsToExport to @() in a module manifest?
Setting FunctionsToExport to an empty array @() means no functions will be exported from the module. Users won’t be able to call any functions directly from the module.
Click to reveal answer
What file extension does a PowerShell module manifest use?
A.ps1
B.psd1
C.psm1
D.psm
✗ Incorrect
A PowerShell module manifest file always uses the .psd1 extension.
Which cmdlet creates a new module manifest?
ANew-ModuleManifest
BNew-Module
CNew-ScriptManifest
DNew-ManifestFile
✗ Incorrect
The cmdlet New-ModuleManifest is designed to create a new module manifest file.
What does the RequiredModules property in a manifest specify?
AFunctions to export
BThe version of PowerShell required
CThe author of the module
DModules that must be installed before this module works
✗ Incorrect
RequiredModules lists other modules that need to be present for this module to function properly.
If you want to hide all functions from users, what should you set FunctionsToExport to?
A@()
B$null
C'*'
DLeave it empty
✗ Incorrect
Setting FunctionsToExport to an empty array @() exports no functions, hiding them from users.
Which property in a manifest file specifies the module's version?
AManifestVersion
BVersion
CModuleVersion
DModuleNumber
✗ Incorrect
ModuleVersion is the property used to specify the version of the module.
Explain what a PowerShell module manifest (.psd1) file is and why it is useful.
Think about how a manifest helps PowerShell understand your module.
You got /4 concepts.
List and describe at least three important properties you can set in a PowerShell module manifest.
Focus on properties that control module info and behavior.
You got /4 concepts.
Practice
(1/5)
1. What is the primary purpose of a PowerShell module manifest (.psd1)?
easy
A. To store user credentials for the module
B. To execute the module's main script
C. To describe the module's metadata and control its behavior
D. To compile the module into an executable file
Solution
Step 1: Understand what a module manifest is
A module manifest is a file that contains metadata about the module, such as version, author, and dependencies.
Step 2: Identify the manifest's role
It controls what parts of the module are visible and required, helping users understand and use the module properly.
Final Answer:
To describe the module's metadata and control its behavior -> Option C
Quick Check:
Manifest = metadata and control [OK]
Hint: Manifest files describe modules, not run code [OK]
Common Mistakes:
Thinking the manifest runs the module code
Confusing manifest with script files
Assuming manifest stores credentials
2. Which of the following is the correct syntax to specify the module version in a .psd1 manifest file?
easy
A. 'ModuleVersion' = '1.0.0'
B. ModuleVersion: 1.0.0
C. ModuleVersion = 1.0.0
D. "ModuleVersion" : "1.0.0"
Solution
Step 1: Recall .psd1 file syntax
A .psd1 file uses a hashtable syntax with key-value pairs, where keys are strings in quotes and values are assigned with '='.
Step 2: Match correct syntax for version
The correct syntax is a string key in quotes, an equals sign, and the version string in quotes: 'ModuleVersion' = '1.0.0'
Final Answer:
'ModuleVersion' = '1.0.0' -> Option A
Quick Check:
Hashtable key-value with '=' and quotes [OK]
Hint: Use quotes and '=' for keys and values in .psd1 [OK]
Common Mistakes:
Using colon instead of equals sign
Omitting quotes around keys or values
Using JSON style syntax
3. Given this snippet from a module manifest (.psd1):
When importing the module, you get an error. What is the problem?
medium
A. The manifest file must not contain RootModule key
B. RootModule must be a script file, not a module file
C. FunctionsToExport cannot contain more than one function
D. FunctionsToExport should be an array, not a list of strings without @()
Solution
Step 1: Check FunctionsToExport syntax
FunctionsToExport expects an array of strings, which requires the @() syntax in PowerShell.
Step 2: Identify the error cause
Writing 'Get-Data', 'Set-Data' without @() is invalid in a hashtable value and causes an error.
Final Answer:
FunctionsToExport should be an array, not a list of strings without @() -> Option D
Quick Check:
Use @() for arrays in manifest [OK]
Hint: Use @() to define arrays in .psd1 manifest [OK]
Common Mistakes:
Omitting @() for arrays
Misunderstanding RootModule usage
Assuming single string can list multiple functions
5. You want your PowerShell module to automatically import a required module and only export one function named 'Invoke-Task'. Which manifest entries should you include?
hard
A. @{ RequiredModules = 'HelperModule'; FunctionsToExport = @('Invoke-Task') }
B. @{ RequiredModules = @('HelperModule'); FunctionsToExport = @('Invoke-Task') }
C. @{ RequiredModules = @('HelperModule'); FunctionsToExport = 'Invoke-Task' }
D. @{ RequiredModules = 'HelperModule'; FunctionsToExport = 'Invoke-Task' }
Solution
Step 1: Define RequiredModules correctly
RequiredModules must be an array of module names, so use @('HelperModule').
Step 2: Define FunctionsToExport correctly
FunctionsToExport must be an array of function names, so use @('Invoke-Task').