powershell profile location

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Ryan Burton Ryan Burton 7 months, 2 weeks ago.

  • Author
    Posts
  • #38402
    Profile photo of Ryan Burton
    Ryan Burton
    Participant

    I am trying to use my old scripts on a new computer and I need to know what folder the powershell profile needs to be placed in. I tried using microsofttechnet, but the answer I got didn't work. This is my profile:

    $a = (Get-Host).UI.RawUI
    $a.BackgroundColor = "black"
    $a.ForegroundColor = "white"
    cls
    $env:path += ";C:\My Documents\PowerShell BACKUP\scripts"

    I am using windows 10

  • #38416
    Profile photo of Richard Diphoorn
    Richard Diphoorn
    Participant

    Hi Ryan, the locations of the profiles can be the following (replace by your own username):

    C:\Windows\system32\WindowsPowerShell\v1.0\profile.ps1
    C:\Windows\system32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
    C:\Windows\system32\WindowsPowerShell\v1.0\Microsoft.PowerShellISE_profile.ps1
    C:\Users\\Documents\WindowsPowerShell\profile.ps1
    C:\Users\\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
    C:\Users\\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1
    

    You will ask yourself, why so many files? Look at this code (executed in a PowerShell console):

    PS C:\> $PROFILE | Select-Object -Property AllUsersAllHosts,AllUsersCurrentHost,CurrentUserAllHosts,CurrentUserCurrentHost | Format-List
    
    AllUsersAllHosts       : C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
    AllUsersCurrentHost    : C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
    CurrentUserAllHosts    : C:\Users\\Documents\WindowsPowerShell\profile.ps1
    CurrentUserCurrentHost : C:\Users\\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
    

    So, here you can see that there are several profile scripts. These don't exist by default, you need to create it.
    If you are the only one using that profile code, and want to use the profile in all the PowerShell shells you are starting,
    create this file and put your code into it: C:\Users\\Documents\WindowsPowerShell\profile.ps1

    If you want to have the profile available in all the PowerShell ISE's that you will start,
    create this file and put your code in: C:\Users\\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1

    The profile files in the system32 directory are ment for All Users, not only you.

    Here's a good reference: https://technet.microsoft.com/en-us/library/bb613488(v=vs.85).aspx

    Also make sure that your execution policy is set to RemoteSigned:

    Set-ExecutionPolicy RemoteSigned
    

    And another tip, Sapien has a specific tool for editing profile files: https://www.sapien.com/software/productivity_pack#PowerShell Profile Editor 2015

  • #38417
    Profile photo of Ryan Burton
    Ryan Burton
    Participant

    ty

You must be logged in to reply to this topic.