Mathias R. Jessen's helpful answer shows that Get-Location returns a System.Management.Automation.PathInfo instance rather than a string and how to account for that.
There is a small caveat, however:
While probably rare in practice, a test based on the returned object's .Path property and the equivalent implicit stringification of the whole object via "..." may still fail, namely if the current location is based on a custom PowerShell drive:
.Path then reports the PowerShell-specific path, whereas $HOME is always expressed as a file-system-native path, so even if the two paths ultimately refer to the same file-system location, -eq will not detect that.
To account for that, use the .ProviderPath property instead, which - just like $HOME - expresses the directory as a file-system-native path:
(Get-Location).ProviderPath -replace '[\\/]$' -eq $HOME
- Note: The unfortunate need for removing a trailing path separator, if present, via
-replace '[\\/]$' stems from the fact that PowerShell, as of v7.0, doesn't normalize what .ProviderPath reports: if the current, PS-drive-based path is the root of that PS drive, .ProviderPath unexpectedly retains the trailing \ (or / on Unix-like platforms) in the native path that is returned.
This problematic behavior is the subject of this GitHub issue.
To give a complete example:
# Define a custom H: drive whose root is $HOME.
$null = New-PSDrive H FileSystem $HOME
# Change to the root of the new drive, which is effectively the
# same as $HOME, though from PowerShell's perspective the path is H:\
Set-Location H:\
# !! -> $false, because .Path reports 'H:\'
(Get-Location).Path -eq $HOME
# OK -> $true - .ProviderPath reports the true, file-system-native path.
# Note:
# If GitHub issue #12971 gets fixed (see above),
# the -replace '[\\/]$' part will no longer be needed.
(Get-Location).ProviderPath -replace '[\\/]$' -eq $HOME
Additionally, if there's a chance that the current location is based on a symbolic link / reparse point, you'll have to do additional work to determine path equality.