Skip to content

$PROFILE is NULL when invoking profile.ps1 and Microsoft.VSCode_profile.ps1 #3662

@Liturgist

Description

@Liturgist

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.

Summary

Here is the output in the TERMINAL window when VSCode PowerShell extension starts. The profile scripts are shown below. When the CurrentUserAllHosts script is run, $PROFILE is NULL. None of these scripts set the value of $PROFILE.

There are two (2) problems.

When one of the non-user profile scripts is invoked (probably AllUsersAllHosts), it appears that the path to the script does not use appropriately placed QUOTATION MARK characters.

When the CurrentUserAllHosts script is run, $PROFILE is NULL.

=====> PowerShell Preview Integrated Console v2021.10.3 <=====

C:\Program: The term 'C:\Program' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Running profile C:\Users\lit\Documents\PowerShell\profile.ps1
PROFILE is NULL
PS C:\Users\lit>

When the TERMINAL command prompt becomes available, the PROFILE variable now contains the following.

PS C:\Users\lit> $PROFILE | Format-List -Property *

AllUsersAllHosts       : C:\Program Files\PowerShell\7\profile.ps1
AllUsersCurrentHost    : C:\Program Files\PowerShell\7\Microsoft.VSCode_profile.ps1
CurrentUserAllHosts    : C:\Users\lit\Documents\PowerShell\profile.ps1
CurrentUserCurrentHost : C:\Users\lit\Documents\PowerShell\Microsoft.VSCode_profile.ps1

These are the profile scripts. Note that both of the Microsoft.VSCode_profile.ps1 files do not exist.

PS C:\> Get-Content -Path 'C:\Program Files\PowerShell\7\profile.ps1'
$s = $($MyInvocation.MyCommand.Source)
Write-Host "Running profile $s"
if ($null -eq $PROFILE) {
    Write-Host "PROFILE is NULL"
} else {
    Write-Host "PROFILE is of type $($PROFILE.GetType())"

    $scope = $PROFILE |
        Get-Member -Type NoteProperty |
        Where-Object { $_.Definition.EndsWith($s) } |
        ForEach-Object { $_.Name }
    Write-Host "$($PSVersionTable.PSVersion.ToString()) $scope @ $($MyInvocation.MyCommand.Source)"
}
PS C:\> Get-Content -Path 'C:\Program Files\PowerShell\7\Microsoft.VSCode_profile.ps1'
Get-Content: Cannot find path 'C:\Program Files\PowerShell\7\Microsoft.VSCode_profile.ps1' because it does not exist.
PS C:\> Get-Content -Path 'C:\Users\lit\Documents\PowerShell\profile.ps1'
$s = $($MyInvocation.MyCommand.Source)
Write-Host "Running profile $s"
if ($null -eq $PROFILE) {
    Write-Host "PROFILE is NULL"
} else {
    Write-Host "PROFILE is of type $($PROFILE.GetType())"

    $scope = $PROFILE |
        Get-Member -Type NoteProperty |
        Where-Object { $_.Definition.EndsWith($s) } |
        ForEach-Object { $_.Name }
    Write-Host "$($PSVersionTable.PSVersion.ToString()) $scope @ $($MyInvocation.MyCommand.Source)"
}
PS C:\> Get-Content -Path 'C:\Users\lit\Documents\PowerShell\Microsoft.VSCode_profile.ps1'
Get-Content: Cannot find path 'C:\Users\lit\Documents\PowerShell\Microsoft.VSCode_profile.ps1' because it does not exist.
PS C:\>

PowerShell Version

PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.1.5
PSEdition                      Core
GitCommitId                    7.1.5
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visual Studio Code Version

PS C:\> code --version
1.61.2
6cba118ac49a1b88332f312a8f67186f7f3c1643
x64

Extension Version

PS C:\> code --list-extensions --show-versions | Select-String powershell

ms-vscode.powershell@2021.10.2
ms-vscode.powershell-preview@2021.10.3

Steps to Reproduce

Start VSCode powershell extension with profile scripts included above.

Visuals

No response

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions