Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8147955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:31:56+00:00 2026-06-06T14:31:56+00:00

When you use a .NET object from PowerShell, and it takes a filename, it

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:31:58+00:00Added an answer on June 6, 2026 at 2:31 pm

    The reasons PowerShell doesn’t keep the .NET notion of current working directory in sync with PowerShell’s notion of the working dir are:

    1. PowerShell working dirs can be in a provider that isn’t even file system
      based e.g. HKLM:\Software
    2. A single PowerShell process can have
      multiple runspaces. Each runspace can be cd`d into a different file
      system location. However the .NET/process “working directory” is
      essentially a global for the process and wouldn’t work for a
      scenario where there can be multiple working dirs (one per runspace).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a COM object that I'm trying to use from C++ (not .NET),
In .Net, I'm trying to get a XmlSchema object from Xml file with an
I am trying to use Powershell to get file names from a network folder.
I use JSON.NET and I would like to parse the following object which I
I started to use Json.NET to convert a string in JSON format to object
In a scientific application I'm writing (vb.net) I use a huge collection of object
I have a .net object that I want to use in Excel. I have
When you interface a COM object from .NET code, VS creates an interop DLL,
I receive an object from the net through the the getInputStream() using ObjectInputStream My
We are accessing a .NET object from matlab. It's some image capture software, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.