When you use a .NET object from PowerShell, and it takes a filename, it always seems to be relative to C:\Windows\System32
.
For example:
[IO.File]::WriteAllText('hello.txt', 'Hello World')
...will write C:\Windows\System32\hello.txt
, rather than C:\Current\Directory\hello.txt
Why does PowerShell do this? Can this behaviour be changed? If it can't be changed, how do I work around it?
I've tried Resolve-Path
, but that only works with files that already exist, and it's far too verbose to be doing all the time.