G
G
Gennady2016-02-16 08:19:25
PowerShell
Gennady, 2016-02-16 08:19:25

What's wrong with rights?

Good morning!
I am writing this simple code. Task: create a test.txt file in each D:\testfolder (it contains three baseX folders)

$test = Get-ChildItem D:\testfolder -Recurse | Where-Object {Test-Path $_.FullName -PathType container}

Foreach ($dir in $test)
    {
        New-Item -Value test.txt -Path $dir.FullName -ItemType file
    }

The script throws an error (for each file created)
New-Item : Отказано в доступе по пути "D:\testfolder\base1".
строка:7 знак:9
+         New-Item -Value test.txt -Path $dir.FullName -ItemType file
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (D:\testfolder\base1:String) [New-Item], UnauthorizedAccessException
    + FullyQualifiedErrorId : NewItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.NewItemCommand

I can't fight it at all. With rights, everything should be fine, tk. under that user under which I start a script, the rights to this folder are. Tried running powershell_ise as admin - same thing. Tell me why there are not enough rights? Can't get in at all

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2016-02-16
@genana40

uh, carefully read the output of the
get-help new-item -examples command ,
especially examples with value
kmk, you mixed up the parameters. value was used instead of name. The first is used for the name of the item, the second for its content.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question