Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm sure this has been asked a million times, but I can't figure out why I can't run this simple command in powershell:

PS> new-item -path c:\users\me\desktop\testfolder -name (get-date).txt -value (get-date).toString() -itemtype file

I am forever getting the following error:

New-Item : Access to the path 'C:\Users\Me\desktop\testfolder' is denied.

... PermissionDenied: ... UnauthorizedAccessException
... FullyQualifiedErrorId: NewItemUnauthorizedAccessError,Microsoft.PowerShell...


I've tried ALL of the following, to no avail:

  • Running powershell as Administrator (i.e, "Run as Administrator")
  • Set-ExecutionPolicy RemoteSigned
  • "takeown" on the folder
  • setting the security settings on the folder to: "everyone > full control"
  • -FORCE

Where the heck should I go hunting for an answer next? I'm an administrator on my local machine. This is extremely frustrating not to have rights to do something as simple as creating a stupid text file...

Pulling hair-out...

share|improve this question
Have you tried with the -Force parameter? – EBGreen Jan 25 '12 at 15:48
just tried, same error (i'll add that to my above list now) – ErOx Jan 25 '12 at 15:53
Did some test on XP, can't create files or folders in user folders (in my case C:\Documents and Settings). I can perform this in C:\ however. Has to do something with ACLs or the like. – Mechaflash Jan 25 '12 at 16:40

The the DateTime string format returned by Get-Date contains characters that can't be used for file names. Try something like this:

new-item -path .\desktop\testfolder -name "$(get-date -format 'yyyyMMdd_HHmm').txt" `
        -value (get-date).toString() -itemtype file

Just change the format string to meet your needs.

share|improve this answer
Duh...good catch. – EBGreen Jan 25 '12 at 16:56

The issue is that -name (get-date).txt is not the same as (get-date) + ".txt". The former will try to read a property named "txt" on the returned System.DateTime object, and the latter will append the string ".txt" to a string representation of the date. In the former, .txt as a property returns $null because it does not exist. This, in turn, means you're trying to effectively run new-item -path .\desktop\folder which returns access denied because folder already exists.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.