Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 26, 2025

Problem

Users with restrictive company policies that prevent setting PowerShell ExecutionPolicy at the CurrentUser scope were unable to use the PCF Builder tool. The tool previously required Set-ExecutionPolicy -Scope CurrentUser which violates many corporate security policies, but could work with Set-ExecutionPolicy -Scope Process which only affects the current session.

Solution

This PR adds configurable PowerShell ExecutionPolicy support through a new settings UI, allowing users to specify their preferred execution policy while maintaining backward compatibility with the original behavior.

Key Changes

Settings UI Enhancement:

  • Added new "PowerShell Execution Policy" field in the Settings form
  • Users can specify custom PowerShell execution policy parameters
  • Field positioned between "MS Build Path" and "Namespace" for logical grouping

Settings Form

Smart Execution Policy Logic:

  • Modified InitCommandLine() to use custom execution policy if provided, otherwise use original default
  • Updated FindMsBuildPath() method to respect user's custom execution policy
  • Preserved original SetExecutionPolicyToUnrestricted() behavior as default fallback

New Methods Added:

// For custom execution policy support
public static string SetCustomExecutionPolicy(string customPolicy)
public static string SetCustomExecutionPolicyWrapped(string customPolicy)

New Settings Property:

public string CustomExecutionPolicy { get; set; }

Usage Examples

Default Behavior (Empty field):

powershell "& "Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser -force""
powershell "& "msbuild-script.ps1""
powershell "& "Set-ExecutionPolicy -ExecutionPolicy Default -Scope CurrentUser -force""

Custom Policy (User enters: -ExecutionPolicy Bypass -Scope Process -force):

cmd /K powershell -Command "Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -force"

Custom Policy (User enters: -ExecutionPolicy RemoteSigned -Scope CurrentUser -force):

cmd /K powershell -Command "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -force"

Benefits

  • Backward Compatible: Empty field uses original behavior (Unrestricted CurrentUser)
  • Flexible: Supports any valid PowerShell execution policy syntax
  • User-Controlled: No assumptions about user's environment or policies
  • Corporate Policy Compliant: Users can specify company-approved policies like Process scope
  • Consistent: Same policy used for both interactive sessions and background operations

This change resolves the issue where users couldn't use the tool due to company ExecutionPolicy restrictions, while providing maximum flexibility and maintaining full backward compatibility.

Fixes #73

Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature]: Allow Powershell scripts in session</issue_title>
<issue_description>### Contact Details

nicklas.hansen@twoday.com

Is your feature request related to a problem?

Yes

Describe the problem?

When using the PCF Building tool, I’m blocked by a company policy requiring ExecutionPolicy Bypass.
I can only set it per session (-Scope Process), but I can’t run this in the tool’s embedded CMD before commands execute.
Since the change must happen in the same CMD session as the build command, there’s currently no way to do this inside the tool.

Provide a solution or an idea you would like to see in the tool?

Request: Add a way to set ExecutionPolicy Bypass -Scope Process automatically or allow running a custom initialization command before the build starts.

Relevant log output

```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>
Fixes #73

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits September 26, 2025 06:11
Co-authored-by: Power-Maverick <36135520+Power-Maverick@users.noreply.github.com>
Co-authored-by: Power-Maverick <36135520+Power-Maverick@users.noreply.github.com>
Copilot AI changed the title [WIP] [Feature]: Allow Powershell scripts in session Add support for PowerShell ExecutionPolicy Bypass with Process scope Sep 26, 2025
Copy link
Owner

@Power-Maverick Power-Maverick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Keep the original code where unrestricted bypass was set.
  • Add additional features on the settings page that will allow user to provide the bypass policy to use
  • If user has provided the bypass policy use that instead of the default one

@Power-Maverick
Copy link
Owner

@copilot make the necessary changes

  • Keep the original code where unrestricted bypass was set.
  • Add additional features on the settings page that will allow user to provide the bypass policy to use
  • If user has provided the bypass policy use that instead of the default one

Co-authored-by: Power-Maverick <36135520+Power-Maverick@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 27, 2025

@copilot make the necessary changes

  • Keep the original code where unrestricted bypass was set....

I've implemented the requested changes in commit ccd870c:

Kept original code: Restored default behavior using SetExecutionPolicyToUnrestricted()
Added settings UI: New "PowerShell Execution Policy" field in settings page
Smart fallback: Uses custom policy if provided, otherwise falls back to original behavior

How it works:

  • Empty field (default): Uses original Unrestricted -Scope CurrentUser behavior
  • Custom policy: User can enter any valid PowerShell execution policy syntax
  • Example: -ExecutionPolicy Bypass -Scope Process -force for company policies requiring process scope

Settings Form UI:
Settings Form

The new field is positioned between "MS Build Path" and "Namespace" and works for both interactive PowerShell sessions and background MSBuild operations.

Copilot AI changed the title Add support for PowerShell ExecutionPolicy Bypass with Process scope Add configurable PowerShell ExecutionPolicy support with settings UI Sep 27, 2025
@Power-Maverick Power-Maverick marked this pull request as ready for review September 28, 2025 21:07
Copilot AI review requested due to automatic review settings September 28, 2025 21:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds configurable PowerShell ExecutionPolicy support to resolve corporate policy restrictions that prevented users from using the PCF Builder tool. The enhancement allows users to specify custom ExecutionPolicy parameters through a new settings UI field while maintaining backward compatibility.

  • Added new "PowerShell Execution Policy" field in Settings form for custom ExecutionPolicy configuration
  • Modified command initialization logic to use custom ExecutionPolicy when specified
  • Added new helper methods for custom ExecutionPolicy handling with fallback to original behavior

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

File Description
Settings.cs Added CustomExecutionPolicy property to store user's preferred ExecutionPolicy parameters
SettingsForm.cs Integrated new ExecutionPolicy text field into Settings UI for user configuration
PCFBuilder.cs Modified InitCommandLine and FindMsBuildPath methods to use custom ExecutionPolicy when available
Commands.cs Added helper methods for custom ExecutionPolicy support with backward compatibility
Files not reviewed (1)
  • Maverick.PCF.Builder/Forms/SettingsForm.Designer.cs: Language not supported

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Power-Maverick and others added 5 commits September 28, 2025 19:07
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Removed default PowerShell initialization and added support for
dynamic custom execution policies via `pluginSettings`. A success
message is now displayed in the console when a custom policy is
applied, enhancing flexibility and user feedback.
@Power-Maverick Power-Maverick merged commit 853d5f6 into master Sep 30, 2025
2 checks passed
@Power-Maverick Power-Maverick deleted the copilot/fix-56c38257-6850-4666-9ae7-98f0c41da468 branch September 30, 2025 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Allow Powershell scripts in session

2 participants