Windows 2022
Sponsored Link

PowerShell : Set Profile
2022/12/23
 
Set Profile it is loaded when PowerShell starts.
[1] By default, Profile does not exist, so create it first and set any commands or variables you like.
# make sure own profile's PATH
PS C:\Users\Administrator> Write-Output $profile 
C:\Users\Administrator\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

PS C:\Users\Administrator> Get-Item $profile 

# none by default
Get-Item : Cannot find path 'C:\Users\Administrator\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1' because it
does not exist.
At line:1 char:1
+ Get-Item $profile
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\Admini...ell_profile.ps1:String) [Get-Item], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand

# create it
PS C:\Users\Administrator> New-Item $profile -type file -force 

    Directory: C:\Users\Administrator\Documents\WindowsPowerShell


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        12/23/2022  12:19 AM              0 Microsoft.PowerShell_profile.ps1


# for example, set command that shows messages in $profile
PS C:\Users\Administrator> Write-Output 'Write-Output "This message is from $profile"' > $profile 
PS C:\Users\Administrator> exit 

# run PowerShell
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows

This message is from C:\Users\Administrator\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
PS C:\Users\Administrator>
Matched Content