-
Notifications
You must be signed in to change notification settings - Fork 8k
DSC v3 resource for Powershell Profile #26157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
DSC v3 resource for Powershell Profile #26157
Conversation
parameters: | ||
- name: dscVersion | ||
type: string | ||
default: 'v3.2.0-preview.4' |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
"content": { | ||
"title": "Content", | ||
"description": "The content of the profile.", | ||
"type": "string" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
if ($InputResource.content) { | ||
Set-Content -Path $profilePath -Value $InputResource.content | ||
} | ||
else { | ||
Remove-Item -Path $profilePath -Force | ||
} |
There was a problem hiding this comment.
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.
if ($inputJson) { | ||
$InputResource = [PwshResource]::new() | ||
$InputResource.profileType = $inputJson.profileType | ||
$InputResource.content = $inputJson.content | ||
$InputResource._exist = $inputJson._exist | ||
} |
There was a problem hiding this comment.
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.
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:
pwsh.profile.resource.ps1
PowerShell script implementing get, set, and export operations for PowerShell profile management, supporting multiple profile types and existence checks.pwsh.profile.dsc.resource.json
manifest describing the resource, its schema, supported operations, and integration details for DSC v3.Experimental Feature Registration:
PSProfileDSCResource
in both Linux and Windows experimental feature lists (experimental-feature-linux.json
,experimental-feature-windows.json
).PSProfileDSCResource
as an internal constant and registered it as an experimental feature with a descriptive summary inExperimentalFeature.cs
. [1] [2]Build and Packaging Updates:
powershell-win-core.csproj
to include all files from thedsc
directory in the output and publish directories, ensuring the new resource is distributed with builds..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:
Get current user all host
PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright header