PowerShell/docs/write-powershell-profile.md

66 lines
1.6 KiB
Markdown
Raw Normal View History

2024-01-03 12:11:22 +01:00
*write-powershell-profile.ps1*
================
This PowerShell script writes the PowerShell profile for the current user.
Parameters
----------
```powershell
PS> ./write-powershell-profile.ps1 [<CommonParameters>]
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
```
Example
-------
```powershell
PS> ./write-powershell-profile.ps1
```
Notes
-----
Author: Markus Fleschutz | License: CC0
Related Links
-------------
https://github.com/fleschutz/PowerShell
Script Content
--------------
```powershell
<#
.SYNOPSIS
Writes the user's PowerShell profile
.DESCRIPTION
This PowerShell script writes the PowerShell profile for the current user.
.EXAMPLE
PS> ./write-powershell-profile.ps1
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
try {
"⏳ (1/3) Querying path to PowerShell profile 'CurrentUserCurrentHost'..."
$pathToProfile = $PROFILE.CurrentUserCurrentHost
"⏳ (2/3) Creating the profile (if non-existent)..."
$null = New-Item -Path $pathToProfile -ItemType "file" -Force
"⏳ (3/3) Updating the profile by my-profile.ps1..."
Copy-Item "$PSScriptRoot/my-profile.ps1" "$pathToProfile" -force
"✔️ Updated your PowerShell profile - it gets active on next login"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
```
*(generated by convert-ps2md.ps1 using the comment-based help of write-powershell-profile.ps1 as of 01/03/2024 12:10:53)*