Skip to content

Fix Invoke-PnPSiteTemplate parameter set to allow -Path with -InputInstance #5000

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
wants to merge 2 commits into from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 6, 2025

Fixes a parameter set resolution error that prevented using -Path and -InputInstance parameters together in Invoke-PnPSiteTemplate, despite this being documented as supported behavior in Example 9.

Problem

The cmdlet would throw this error when using both parameters:

Invoke-PnPSiteTemplate -Path .\ -InputInstance $template
# Error: Parameter set cannot be resolved using the specified named parameters.

This occurred because the -Path parameter was only defined for the "Path" parameter set, making it mutually exclusive with -InputInstance (which belongs to the "Instance" parameter set).

Solution

Added a second [Parameter] attribute to allow -Path in the "Instance" parameter set as an optional parameter:

[Parameter(Mandatory = true, Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true, ParameterSetName = "Path")]
[Parameter(Mandatory = false, ParameterSetName = "Instance")]
public string Path;

This change:

  • ✅ Preserves existing behavior: -Path remains mandatory in "Path" parameter set
  • ✅ Enables documented behavior: -Path is now optional in "Instance" parameter set for specifying supporting file locations
  • ✅ No breaking changes: All existing parameter combinations continue to work
  • ✅ Implementation ready: The execution logic already supports this scenario (lines 279-294)

Usage

Now works as documented in Example 9:

# Get template instance in memory
$template = Get-PnPSiteTemplate -OutputInstance

# Apply with supporting files from specific path
Invoke-PnPSiteTemplate -InputInstance $template -Path .\supporting-files\

Fixes #4986.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

…ance

Co-authored-by: gautamdsheth <8832018+gautamdsheth@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] [BUG] Invoke-PnPSiteTemplate with -InputInstance does not accept -Path Fix Invoke-PnPSiteTemplate parameter set to allow -Path with -InputInstance Jul 6, 2025
Copilot finished work on behalf of gautamdsheth July 6, 2025 17:41
@Copilot Copilot AI requested a review from gautamdsheth July 6, 2025 17:41
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Invoke-PnPSiteTemplate with -InputInstance does not accept -Path
2 participants