Giter Club home page Giter Club logo

powershellprofile's Introduction

Powershell profile for efficiency gains ๐Ÿ’ช

A PowerShell profile is a script that runs when PowerShell starts. You can use the profile as a startup script to customize your environment. You can add commands, aliases, functions, variables, modules, PowerShell drives and more. You can also add other session-specific elements to your profile so they're available in every session without having to import or re-create them.

PowerShell supports several profiles for users and host programs. However, it doesn't create the profiles for you.

RTFM:

Link to Microsoft Doc - about_profiles

Profile types and locations

PowerShell supports several profile files that are scoped to users and PowerShell hosts. You can have any or all these profiles on your computer.

For example, the PowerShell console supports the following basic profile files. The profiles are listed in order that they're executed.

All Users, All Hosts
    Windows - $PSHOME\Profile.ps1
    Linux - /opt/microsoft/powershell/7/profile.ps1
    macOS - /usr/local/microsoft/powershell/7/profile.ps1
All Users, Current Host
    Windows - $PSHOME\Microsoft.PowerShell_profile.ps1
    Linux - /opt/microsoft/powershell/7/Microsoft.PowerShell_profile.ps1
    macOS - /usr/local/microsoft/powershell/7/Microsoft.PowerShell_profile.ps1
Current User, All Hosts
    Windows - $HOME\Documents\PowerShell\Profile.ps1
    Linux - ~/.config/powershell/profile.ps1
    macOS - ~/.config/powershell/profile.ps1
Current user, Current Host
    Windows - $HOME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
    Linux - ~/.config/powershell/Microsoft.PowerShell_profile.ps1
    macOS - ~/.config/powershell/Microsoft.PowerShell_profile.ps1

The profile scripts are executed in the order listed. This means that changes made in the AllUsersAllHosts profile can be overridden by any of the other profile scripts. The CurrentUserCurrentHost profile always runs last. In PowerShell Help, the CurrentUserCurrentHost profile is the profile most often referred to as your PowerShell profile.

Other programs that host PowerShell can support their own profiles. For example, Visual Studio Code (VS Code) supports the following host-specific profiles.

All users, Current Host - $PSHOME\Microsoft.VSCode_profile.ps1
Current user, Current Host - $HOME\Documents\PowerShell\Microsoft.VSCode_profile.ps1

The profile paths include the following variables:

The $PSHOME variable stores the installation directory for PowerShell
The $HOME variable stores the current user's home directory

Check if you have a Profile

$PROFILE | Get-Member -Type NoteProperty

If the response has values for all four values, especially CurrentUserCurrentHost, you have a profile. If not you can create one by using the following command:

if (!(Test-Path -Path $PROFILE)) { New-Item -ItemType File -Path $PROFILE -Force }

You should now have a profile for the current user in the current PowerShell host application.

How to edit a profile

You can open PowerShell profile in any text editor.

notepad $PROFILE
## or vscode
code $PROFILE

To open other profiles, specify the profile name. For example, to open the profile for all the users of all the host applications, type:

code $PROFILE.AllUsersAllHosts

To apply the changes, save the changes, and restart PowerShell or reload the script

. $PROFILE

Link the profile to github file in different location to default path

Create symlink in windows

New-Item -ItemType SymbolicLink -Path "$HOME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1" -Target "$HOME\Documents\GitHub\YourRepo\Microsoft.PowerShell_profile.ps1"

Create symlink in macOS and Linux

ln -s "~/.config/powershell/Microsoft.PowerShell_profile.ps1" "~/Documents/GitHub/YourRepo/profile.ps1"

powershellprofile's People

Contributors

mbonne avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.