PowerShell Core continues to irritate me, almost every time I decide to give it another chance it manages to get on my nerves in some new and ingenious way. Today’s rant is the story of me trying to bring the Profile customizations I’ve made to its beloved older brother, Windows PowerShell, to the current 6.1 release of Core. One of these customizations includes setting the working directory to something more useful than the default “Home” directory.
So I proceeded to add a simple Set-Location cmdlet to my profile script, yet after relaunching PowerShell, it still opened in my home directory. Failing to spot any obvious errors in the simple cmdlet I’ve used, I proceeded to refresh my memory on how PowerShell Core handled profiles, and just in case put the same line in the “system” (All Users, All Hosts) profile. No luck.
Being the experienced debugger that I am, next I did what I know best – wrapped a bunch of Write-Host cmdlets around the Set-Location one. Just to make sure the profile is actually being executed (although I did already know this is happening, due to the other customizations). Even the almighty echo-s didn’t help, and the working directory was clearly being set on some other level, overriding any changes I made to profile.
The first suspect to examine then was the settings on the shortcut I used to launch PowerShell, and I expected to see the “Start in” property populated there, as in fact it is for the Windows PowerShell shortcuts. Although in the case of Windows PowerShell it does not overriding the profile customizations. Anyway, I was wrong on that part and the “Start in” value was empty. However the “Target” value caught my eye, and lo and behold – PowerShell was being invoked with a new -WorkingDirectory switch:
Nasty little bugger! Removing it fixed my issue, and the universe made sense again. And since I wasted half an hour on this, I decided to waste some more time and bitch about it on GitHub. Turns out there is already an issue raised on this, and the fix is merged in the 6.2 Preview release, so I didn’t get to express my frustration as someone beat me to it. But nothing stops me from doing so here on my blog 🙂
Hopefully others will not have to suffer the same, once the 6.2 version has GAd. Until then, if you run into this annoyance, simply remove the -WorkingDirectory parameter from your shortcut(s).
1 thought on “PowerShell Core and setting a working directory via profile script”
It always sad when someone beats you to bitch on something 🙂