Skip to content

Update-PowershellProfile

Updates the user's PowerShell profile

param([string]$path = "$PSScriptRoot/my-profile.ps1")

try {
	"? (1/2) Querying path to PowerShell profile 'CurrentUserCurrentHost'..."
	$pathToProfile = $PROFILE.CurrentUserCurrentHost

	$filename = (Get-Item "$path").Name
	"? (2/2) Copying $filename to $pathToProfile..."
	$null = New-Item -Path $pathToProfile -ItemType "file" -Force
	Copy-Item "$path" "$pathToProfile" -force

	"? PowerShell profile updated - it get's active on next login."
	exit 0 # success
} catch {
	"?? ERROR: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
	exit 1
}

Specifies the path to the new profile ($PSScriptRoot/my-profile.ps1 by default)

An interactive directory of PowerShell scripts.