New-Item creates a file instead of directory/folder

Jonathan Yang 101 Reputation points
2021-05-31T09:16:48.63+00:00

Hi everyone -

I'm stuck with New-Item cmdlet creating a file instead of directory even though I specifically add -ItemType "directory"

Here's my code (inside of a -Scriptblock):
New-Item -Path "c:\" -Name "RXtemp" -ItemType "directory"

However when done using Invoke-Command, it works.
Invoke-Command -computername Target -scriptblock {New-Item -Path "c:\" -Name "RXtemp" -ItemType "directory"}

Am I missing something here?

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2021-06-01T02:49:59.177+00:00

    Hi,

    As RXtemp is 186KB in your screenshot, please check if any other cmdlet in your script writes to the file, e. g., copy-item.

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


2 additional answers

Sort by: Most helpful
  1. Andreas Baumgarten 123.4K Reputation points MVP Volunteer Moderator
    2021-05-31T10:58:05.537+00:00

    Hi @Jonathan Yang ,

    I just tested your code in different variations:

    New-Item -Path "c:\" -Name "RXtemp1" -ItemType Directory  
    New-Item -Path "c:\" -Name "RXtemp2" -ItemType "directory"  
    

    Both lines are creating a folder like expected.

    My PS Version is 5.1.19041.906

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


  2. Adrian Martinez 1 Reputation point
    2021-06-02T01:44:29.36+00:00

    Hello, I know that there are already answers but I think that you need to select the file you want to create
    (There may be a pre set default)

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.