8000 DSC v3 resource for Powershell Profile by adityapatwardhan · Pull Request #26157 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Conversation

adityapatwardhan
Copy link
Member
@adityapatwardhan adityapatwardhan commented Oct 7, 2025

PR Summary

Implement a DSC v3 resource for managing PowerShell Profile.

This pull request introduces a new experimental DSC v3 resource for managing PowerShell profiles, along with the necessary infrastructure to support it across platforms. The main changes include the addition of the resource implementation and manifest, updates to experimental feature lists and registration, and build system modifications to ensure the resource is included in distribution packages.

DSC Resource Implementation:

  • Added pwsh.profile.resource.ps1 PowerShell script implementing get, set, and export operations for PowerShell profile management, supporting multiple profile types and existence checks.
  • Created pwsh.profile.dsc.resource.json manifest describing the resource, its schema, supported operations, and integration details for DSC v3.

Experimental Feature Registration:

  • Registered the new experimental feature PSProfileDSCResource in both Linux and Windows experimental feature lists (experimental-feature-linux.json, experimental-feature-windows.json).
  • Added PSProfileDSCResource as an internal constant and registered it as an experimental feature with a descriptive summary in ExperimentalFeature.cs. [1] [2]

Build and Packaging Updates:

  • Updated powershell-win-core.csproj to include all files from the dsc directory in the output and publish directories, ensuring the new resource is distributed with builds.
  • Added a new Azure Pipelines configuration .vsts-ci/dsc-resource.yml for building, testing, and installing DSC resources, including steps for environment setup and functional testing.

PR Context

Export all profiles:

 dsc resource export --resource Microsoft.PowerShell/Profile

  PS D:\PSGit\PowerShell> dsc resource export --resource Microsoft.PowerShell/Profile
  $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
  contentVersion: 1.0.0
  resources:
  - type: Microsoft.PowerShell/Profile
    name: AllUsersCurrentHost
    properties:
      profileType: AllUsersCurrentHost
      content: "Write-Host 'Welcome to your PowerShell profile - AllUsersCurrentHost!'\r\n"
      _exist: true
  - type: Microsoft.PowerShell/Profile
    name: AllUsersAllHosts
    properties:
      profileType: AllUsersAllHosts
      content: "Write-Host 'Welcome to your PowerShell profile - AllUsersAllHosts!'\r\n"
      _exist: true
  - type: Microsoft.PowerShell/Profile
    name: CurrentUserAllHosts
    properties:
      profileType: CurrentUserAllHosts
      content: "# Test profile content currentuser allhosts\r\n"
      _exist: true
  - type: Microsoft.PowerShell/Profile
    name: CurrentUserCurrentHost
    properties:
      profileType: CurrentUserCurrentHost
      content: "Write-Host 'Welcome to your PowerShell profile - CurrentUserCurrentHost!'\r\n"
      _exist: true

Get current user all host

$i = @{ profileType = "CurrentUserAllHosts"} | ConvertTo-Json
dsc resource get --resource Microsoft.PowerShell/Profile -i $i
actualState:
  profileType: CurrentUserAllHosts
  content: '# Test profile content currentuser allhosts'

PR Checklist

@adityapatwardhan adityapatwardhan requested review from a team and jshigetomi as code owners October 7, 2025 19:54
@adityapatwardhan adityapatwardhan changed the title Dsc resource profile DSC v3 resource for Powershell Profile Oct 7, 2025
@adityapatwardhan adityapatwardhan marked this pull request as draft October 7, 2025 19:57
parameters:
- name: dscVersion
type: string
default: 'v3.2.0-preview.4'
Copy link
Member

Choose a reason for hiding this comment

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

Hardcoding the default here means we have to keep it updated

In your AcquireDsc script, you can do something like:

$releases = invoke-restmethod https://api.github.com/repos/powershell/dsc/releases
$assets = ($releases | Where-Object { $_.prerelease -eq $true } | Select-Object -First 1).assets
$windows_download_url = ($assets | Where-Object { $_.name -like '*-x86_64-pc-windows-msvc.zip' }).browser_download_url

This will return

Copy link
Member Author

Choose a reason for hiding this comment

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

This is going to change with acquisition from feed

@microsoft-github-policy-service microsoft-github-policy-service bot added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept labels Oct 7, 2025
Comment on lines +65 to +68
"content": {
"title": "Content",
"description": "The content of the profile.",
"type": "string"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is okay for the first release, though manually defining the entire blob isn't very ergonomic. There's no way to simply ensure the start of the profile includes required lines, for example.

I'm not advocating for slowing this PR, but I do think users will ask for more flexibility, and with the resource shipping with pwsh itself, I suspect the update cycle will be relatively slow.

Copy link
Member Author

Choose a reason for hiding this comment

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

We discussed earlier that the first version will just clobber. We can add prepend / append later.

Comment on lines +115 to +120
if ($InputResource.content) {
Set-Content -Path $profilePath -Value $InputResource.content
}
else {
Remove-Item -Path $profilePath -Force
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a little surprising - if I understand correctly, the following snippet will remove the current user current host profile:

- type: Microsoft.PowerShell/Profile
  name: Personal PowerShell profile
  properties:
    _exist: true

I would expect it to be left alone if it already exists or create an empty file if it doesn't exist.

Comment on lines +132 to +137
if ($inputJson) {
$InputResource = [PwshResource]::new()
$InputResource.profileType = $inputJson.profileType
$InputResource.content = $inputJson.content
$InputResource._exist = $inputJson._exist
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this commen 9901 t to others. Learn more.

I think we need to do some more handling here to determine whether or not the user explicitly defined content in the input - if they did, we want to control that content. If they didn't, we want to leave the content alone.

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.

3 participants
0