In a PowerShell console, the $PROFILE variable is a [string]. Why is it not a [string] in VS Code?
PS C:\> $PROFILE
C:\Users\pwatson2\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
PS C:\> $PROFILE.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
PS C:\> $PSVersionTable.PSVersion.ToString()
7.1.5
In the VS Code terminal it is a [PSCustomObject].
[DBG]: PS C:\> $PROFILE
AllUsersAllHosts AllUsersCurrentHost CurrentUserAllHosts
---------------- ------------------- -------------------
C:\Program Files\PowerShell\7\profile.ps1 C:\Program Files\PowerShell\7\Microsoft.VSCode_profile.ps1 C:\Users\pwatson2\Docu…
[DBG]: PS C:\> $PROFILE.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False PSCustomObject System.Object
[DBG]: PS C:\> $PSVersionTable.PSVersion.ToString()
7.1.5
UPDATE:
<dropped for clarity>
UPDATE 2:
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:\>