Skip to content
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

Export-PSProfileConfiguration contains machine / user specific properties #37

Closed
codaamok opened this issue Jun 15, 2020 · 8 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@codaamok
Copy link
Contributor

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
Copy link
Member

scrthq commented Jun 20, 2020

Checking this out, thanks @codaamok ♥️

@scrthq scrthq self-assigned this Jun 21, 2020
@scrthq scrthq added the bug Something isn't working label Jun 21, 2020
@scrthq
Copy link
Member

scrthq commented Jun 21, 2020

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

  • Working on preventing those $env:ComputerName and $env:UserName vars from being set other than what they should be set to on the current machine
  • That path is set by Configuration but I was planning on adding a spot to load in a separate config from a defined/custom path to layer against it. This would let you first import whatever is at $PSProfile.Settings.ConfigurationPath, then import the custom path on top of it (whatever is layered on last should take precedence in the event there are conflicts) --- would that satisfy the ask around the side question?

@codaamok
Copy link
Contributor Author

Yes, that sounds like a really good solution!

scrthq added a commit that referenced this issue Jun 27, 2020
@scrthq
Copy link
Member

scrthq commented Jun 27, 2020

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

@scrthq scrthq closed this as completed Jun 27, 2020
@codaamok
Copy link
Contributor Author

codaamok commented Jul 1, 2020

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
Copy link
Contributor Author

codaamok commented Jul 1, 2020

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
Copy link
Member

scrthq commented Jul 1, 2020

@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
Copy link
Contributor Author

codaamok commented Jul 4, 2020

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.

  • PluginPaths
  • Settings.ConfigurationPath

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants