1
0
mirror of https://github.com/fleschutz/PowerShell.git synced 2025-04-14 14:08:17 +02:00

Updated write-powershell-profile.ps1

This commit is contained in:
Markus Fleschutz 2024-02-28 07:44:20 +01:00
parent 680f99568d
commit edd15f6ebe

View File

@ -1,27 +1,35 @@
<# <#
.SYNOPSIS .SYNOPSIS
Writes the user's PowerShell profile Writes the PowerShell profile
.DESCRIPTION .DESCRIPTION
This PowerShell script writes the PowerShell profile for the current user. This PowerShell script writes the PowerShell profile for the current user.
.PARAMETER path
Specifies the path to the new profile ($PSScriptRoot/my-profile.ps1 by default)
.EXAMPLE .EXAMPLE
PS> ./write-powershell-profile.ps1 PS> ./write-powershell-profile.ps1
(1/2) Querying path to profile 'CurrentUserCurrentHost'...
C:\Users\Markus\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
(2/2) Copying file 'my-profile.ps1'...
New PowerShell profile written - it gets active on next login
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
Author: Markus Fleschutz | License: CC0 Author: Markus Fleschutz | License: CC0
#> #>
param([string]$path = "$PSScriptRoot/my-profile.ps1")
try { try {
"⏳ (1/3) Querying path to PowerShell profile 'CurrentUserCurrentHost'..." "⏳ (1/2) Querying path to profile 'CurrentUserCurrentHost'..."
$pathToProfile = $PROFILE.CurrentUserCurrentHost $pathToProfile = $PROFILE.CurrentUserCurrentHost
" $pathToProfile"
"⏳ (2/3) Creating the profile (if non-existent)..." $filename = (Get-Item "$path").Name
"⏳ (2/2) Copying file '$filename'..."
$null = New-Item -Path $pathToProfile -ItemType "file" -Force $null = New-Item -Path $pathToProfile -ItemType "file" -Force
Copy-Item "$path" "$pathToProfile" -force
"⏳ (3/3) Updating the profile by my-profile.ps1..." "✔️ New PowerShell profile written - it gets active on next login"
Copy-Item "$PSScriptRoot/my-profile.ps1" "$pathToProfile" -force
"✔️ Updated your PowerShell profile - it gets active on next login"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"