none
Incorrect profile

    Question

  • Why does powershell shows $profile value that doesn't exist?

    PS C:\Users\sri> echo $profile

    C:\Users\sri\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

    PS C:\Users\sri> notepad $profile

    If open with notepad, it says 'System cannot find the specified path'

    There's no 'Documents' folder, it's 'My Documents' and there's no WindowsPowerShell folder within this either



    sri

    Monday, November 04, 2013 9:13 PM

Answers

  • Hi,

    This is one of the places that PowerShell looks for a profile file when you start your session.

    Taken from about_profile (you should take the time and read it - help about_profile)

    THE

    PROFILE FILES

       Windows PowerShell supports several profile files. Also, Windows PowerShell
       host programs can support their own host-specific profiles.

       For example, the Windows PowerShell console supports the following basic
       profile files. The profiles are listed in precedence order. The first
       profile has the highest precedence.


           Description                Path
           -----------                ----
           Current User, Current Host $Home\[My ]Documents\WindowsPowerShell\Profile.ps1
           Current User, All Hosts    $Home\[My ]Documents\Profile.ps1
           All Users, Current Host    $PsHome\Microsoft.PowerShell_profile.ps1
           All Users, All Hosts       $PsHome\Profile.ps1

    HTH.

    G-P

    • Edited by Get-PowerShell Monday, November 04, 2013 9:42 PM
    • Marked as answer by ysrini Monday, November 04, 2013 11:34 PM
    Monday, November 04, 2013 9:40 PM
  • I think your question has been answered, but I wanted to point out something about $profile that is not obvious.

    Although $profile is a String, it is defined to have several special "NoteProperty" values associated with it that have the values of all the various paths that are potential PowerShell startup scripts.

    <# C: #> $profile.gettype()
    IsPublic IsSerial Name                                     BaseType
    -------- -------- ----                                     --------
    True     True     String                                   System.Object
    
    
    <# C: #> $profile | gm -type noteproperty
    
       TypeName: System.String
    
    Name                   MemberType   Definition
    ----                   ----------   ----------
    AllUsersAllHosts       NoteProperty System.String AllUsersAllHosts=C:\Windows\System32\WindowsPowerShell\v1.0\profil...
    AllUsersCurrentHost    NoteProperty System.String AllUsersCurrentHost=C:\Windows\System32\WindowsPowerShell\v1.0\Mic...
    CurrentUserAllHosts    NoteProperty System.String CurrentUserAllHosts=C:\Users\Larry\Documents\WindowsPowerShell\pro...
    CurrentUserCurrentHost NoteProperty System.String CurrentUserCurrentHost=C:\Users\Larry\Documents\WindowsPowerShell\...
    
    <# C: #> $profile | fl -force
    AllUsersAllHosts       : C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
    AllUsersCurrentHost    : C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
    CurrentUserAllHosts    : C:\Users\Larry\Documents\WindowsPowerShell\profile.ps1
    CurrentUserCurrentHost : C:\Users\Larry\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
    Length                 : 75
    
     

    • Marked as answer by ysrini Monday, November 04, 2013 11:34 PM
    Monday, November 04, 2013 11:29 PM
  • and to further clarify G-P's reply a bit, none of those profile scripts exist by default. If you want to use that functionality, the corresponding file needs to be created first.


    Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.

    • Marked as answer by ysrini Monday, November 04, 2013 11:34 PM
    Monday, November 04, 2013 10:06 PM

All replies

  • Hi,

    This is one of the places that PowerShell looks for a profile file when you start your session.

    Taken from about_profile (you should take the time and read it - help about_profile)

    THE

    PROFILE FILES

       Windows PowerShell supports several profile files. Also, Windows PowerShell
       host programs can support their own host-specific profiles.

       For example, the Windows PowerShell console supports the following basic
       profile files. The profiles are listed in precedence order. The first
       profile has the highest precedence.


           Description                Path
           -----------                ----
           Current User, Current Host $Home\[My ]Documents\WindowsPowerShell\Profile.ps1
           Current User, All Hosts    $Home\[My ]Documents\Profile.ps1
           All Users, Current Host    $PsHome\Microsoft.PowerShell_profile.ps1
           All Users, All Hosts       $PsHome\Profile.ps1

    HTH.

    G-P

    • Edited by Get-PowerShell Monday, November 04, 2013 9:42 PM
    • Marked as answer by ysrini Monday, November 04, 2013 11:34 PM
    Monday, November 04, 2013 9:40 PM
  • and to further clarify G-P's reply a bit, none of those profile scripts exist by default. If you want to use that functionality, the corresponding file needs to be created first.


    Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.

    • Marked as answer by ysrini Monday, November 04, 2013 11:34 PM
    Monday, November 04, 2013 10:06 PM
  • I think your question has been answered, but I wanted to point out something about $profile that is not obvious.

    Although $profile is a String, it is defined to have several special "NoteProperty" values associated with it that have the values of all the various paths that are potential PowerShell startup scripts.

    <# C: #> $profile.gettype()
    IsPublic IsSerial Name                                     BaseType
    -------- -------- ----                                     --------
    True     True     String                                   System.Object
    
    
    <# C: #> $profile | gm -type noteproperty
    
       TypeName: System.String
    
    Name                   MemberType   Definition
    ----                   ----------   ----------
    AllUsersAllHosts       NoteProperty System.String AllUsersAllHosts=C:\Windows\System32\WindowsPowerShell\v1.0\profil...
    AllUsersCurrentHost    NoteProperty System.String AllUsersCurrentHost=C:\Windows\System32\WindowsPowerShell\v1.0\Mic...
    CurrentUserAllHosts    NoteProperty System.String CurrentUserAllHosts=C:\Users\Larry\Documents\WindowsPowerShell\pro...
    CurrentUserCurrentHost NoteProperty System.String CurrentUserCurrentHost=C:\Users\Larry\Documents\WindowsPowerShell\...
    
    <# C: #> $profile | fl -force
    AllUsersAllHosts       : C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
    AllUsersCurrentHost    : C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
    CurrentUserAllHosts    : C:\Users\Larry\Documents\WindowsPowerShell\profile.ps1
    CurrentUserCurrentHost : C:\Users\Larry\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
    Length                 : 75
    
     

    • Marked as answer by ysrini Monday, November 04, 2013 11:34 PM
    Monday, November 04, 2013 11:29 PM