SCRT-HQ / PSProfile

PSProfile is a cross-platform PowerShell module built for profile customization. It uses PoshCode's Configuration module to handle the layered Configuration.
Apache License 2.0
46 stars 8 forks source link

Export-PSProfileConfiguration contains machine / user specific properties #37

Closed codaamok closed 4 years ago

codaamok commented 4 years ago

I'd like to use Export-PSProfileConfiguration to export the PSProfile config and use it across multiple machines, however within the psd1 there's multiple properties that would overwrite some environment variables when using Import-PSProfileConfiguration.

Is it possible to make the exported data not include machine or user specific information?

Also, as a side question, is it possible to configure $PSProfile.Settings.ConfigurationPath permanently on a system? Otherwise, I'd imagine the only way to achieve a consistent change to this property is via changing it in profile.ps1 and that invoking a reload of PSProfile.

scrthq commented 4 years ago

Checking this out, thanks @codaamok ♥️

scrthq commented 4 years ago

Alright, here's a more complete response @codaamok :

codaamok commented 4 years ago

Yes, that sounds like a really good solution!

scrthq commented 4 years ago

Heyo @codaamok - Just pushed out v0.6.3 that should get you covered here. Let me know if you have any questions!

codaamok commented 4 years ago

Hello :-) this looks very good, thank you very much.

I have noticed that when I call Add-PSProfileConfigurationPath -Path "C:\somescript.ps1" -Save, then the contents of my current $PSProfile.Settings.ConfigurationPath jump around and the indentation continuously grows for the prompt strings every time I invoke the Add-PSProfileConfigurationPath function. Not a big deal I don't think, but thought you should know as it's probably unintended.

codaamok commented 4 years ago

Sorry to spam! I would also expect the same command (Add-PSProfileConfigurationPath -Path "C:\somescript.ps1" -Save) to update the contents of the configuration file but it doesn't. Unless I'm missing something?

scrthq commented 4 years ago

@codaamok ::

I have noticed that when I call Add-PSProfileConfigurationPath -Path "C:\somescript.ps1" -Save, then the contents of my current $PSProfile.Settings.ConfigurationPath jump around and the indentation continuously grows for the prompt strings every time I invoke the Add-PSProfileConfigurationPath function. Not a big deal I don't think, but thought you should know as it's probably unintended.

I've seen the same and I think it's how Configuration is saving the contents when saved often? I mostly notice it with ScriptBlock's. The end result will always be the same, but if you're looking at the config file, it will be a mess of extraneous indentation. Still trying to nail that one down.

Sorry to spam! I would also expect the same command (Add-PSProfileConfigurationPath -Path "C:\somescript.ps1" -Save) to update the contents of the configuration file but it doesn't. Unless I'm missing something?

It expects a PSD1 file, not a PS1, and will semi-silently skip it if it isn't a PSD1. Ref: https://github.com/SCRT-HQ/PSProfile/blob/main/PSProfile/Public/Configuration/Add-PSProfileConfigurationPath.ps1#L37

codaamok commented 4 years ago

Thanks for all your help so far.

I notice the variables under $PSProfile.Variables.Environment aren't clobbered if the PSProfile configuration is imported by leveraging the $PSProfile.ConfigurationPaths. However they are clobbered if I import using Import-PSProfileConfiguration.

It seems the benefit of using Import-PSProfileConfiguration is that the $PSProfile object is immediately updated within the user's current session. Whereas if I just modify the ConfigurationPaths property, not all the properties (if any) in $PSProfile seem to be updated immediately, even after triggering Update-PSProfileConfig and Refresh-PSProfile.

I'm trying to devise a workflow that enables quick install of my PSProfile configuration and easy update too. An ideal workflow for install and update would work like:

  1. Download PSProfile.Configuration.psd1 from my repo/Gist to somewhere like ~
  2. Import-PSProfileConfiguration ~\PSProfile.Configuration.psd1
  3. Use Add-PSProfilePrompt or similar to modify $PSProfile, or modify the configuration file directly, and use Export-PSProfileConfiguration. Update my repo/Gist with newly exported psd1.
  4. Invoke some custom function that I'll likely store as an init script e.g. Update-Profile that will pull my PSProfile.Configuration.psd1 from my repo or Gist and update ~\PSProfile.Configuration.psd1. Said function will use Import-PSProfileConfiguration once downloaded because it immediately updates $PSProfile without needing to reload.

The problem for me is in step 3, I don't want manually strip out user and machine specific properties before uploading to some location. There's more than just what's under $PSProfile.Variables.Environment which is machine and user specific too, e.g.

I have an idea which might help but I'm not sure how to create in PSProfile. What if Export-PSProfileConfiguration offered some parameter to exclude named properties? That could get a little tricky for usage for the user, e.g. how would they specify child properties such as $PSProfile.Settings.ConfigurationPath in the parameter. But it's probably the most flexible idea because if you just offered a switch instead -ExcludeMachineUserSpecificInfo (terrible name I know, but stick with me) then this means you're deciding for the user what properties they can only exclude with little flexibility.

However, maybe I shouldn't be using Import-PSProfileConfiguration after download and maybe I should just ensure $PSProfile.ConfigurationPaths includes ~\PSProfile.Configuration.psd1 and just reload my session if a new version is detected. What's your opinion?