Allow the addition of custom PowerShell profiles

This commit is contained in:
Manuel Thalmann 2023-07-27 01:55:44 +02:00
parent e44a4244b8
commit 2300d05c87

View file

@ -34,6 +34,22 @@ class Context {
Get-PinnedItem -Type TaskBar | Where-Object { $_.Name -like "$pattern" } | Remove-PinnedItem;
}
[void] AddPowerShellProfileStatement([string] $statement) {
$this.AddPowerShellProfileStatement($null, $statement);
}
[void] AddPowerShellProfileStatement([string] $category, [string] $statement) {
Push-Location ~;
$profileFiles = @((powershell -c '$PROFILE'), (pwsh -c '$PROFILE')) | ForEach-Object { Resolve-Path -Relative $_ };
if ($category) {
$profileFiles = $profileFiles | ForEach-Object { Join-Path (Split-Path -Parent $_) "profile.d" "$category.ps1"; };
}
$profileFiles | ForEach-Object { Add-Content "C:\Users\Default\$_" "`n$statement"; };
Pop-Location;
}
[Microsoft.Win32.RegistryKey] EnsureConfigKey() {
if (-not (Test-Path $this.ConfigRoot)) {
$null = New-Item $this.ConfigRoot;