0

I am trying to set a bunch of files to read-only. However when I call

Set-ItemProperty -LiteralPath $path -Name IsReadOnly -Value $true

it tells me that my path does not exist. The path points to a file which I am sure is present at the stated location. If I follow the path in the explorer I will end up at the file without any problems. Why does it say it does not exist?

1 Answers1

0

Try this:

Set-ItemProperty -Path $path -Name IsReadOnly -Value $true

The parameter you are looking for is "Path" and not "LiteralPath".

Link to Microsoft documentation about Set-ItemProperty: https://technet.microsoft.com/de-de/library/hh849844.aspx

A189198
  • 396
  • 2
  • 7
  • When I use Get-ChildItem with the whole path including the file I get the same error. However when I delete the last bit that is the file name and only have the path to the directory containing the file I get that the folder path is too long. Might this be the issue? – Benjamin S. Sorterup Oct 06 '16 at 06:40
  • ist this your error? The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters. – A189198 Oct 06 '16 at 07:43
  • Yeah when I do Get-ChildItem on the directory containing the file. But when I do Set-ItemProperty on the path including the file. I get: "Set-ItemProperty : Cannot find path $path because it does not exist." Could it be because the path has some illegal characters? I know it contains + and comma. Will that have something to say? – Benjamin S. Sorterup Oct 06 '16 at 08:12
  • If you get the above error on the path, I think that is your problem. That the path is too long. The 260 caracter limit is explained here: http://stackoverflow.com/questions/1880321/why-does-the-260-character-path-length-limit-exist-in-windows – A189198 Oct 06 '16 at 11:11