4

I'm trying to set a few files to writable, but I'm having an issue. I have tried using:

 $file = "path/to/my/file.dat"
 $file = Get-Item $file 
 $file.IsReadOnly = $false

As well as everything listed here:

How to Remove ReadOnly Attribute on File Using PowerShell?

But it still isn't working, at least I don't think it is because when I check the file properties the 'Read-Only' box is still checked:

UPDDATE::

When I run:

$file.isReadOnly

it returns $false, but the box below is explicitly checked? Are these two different things?

enter image description here

I'm wondering what I'm doing wrong, or how to make it so this file is editable.

Community
  • 1
  • 1
BlackHatSamurai
  • 23,275
  • 22
  • 95
  • 156
  • Are you sure you have permissions to the file? Can you post exact result when you run `$file = gi ''; $file.IsReadOnly; $file | Set-ItemProperty -name IsReadOnly -Val $false; (gi '').IsReadOnly` – latkin Aug 01 '13 at 19:12
  • `False False False False False False False False` but the properties box is check as `Read-Only` as the picture above shows. What am I missing? – BlackHatSamurai Aug 01 '13 at 19:15
  • Did you close and re-open the Properties window *after* setting the flag in PowerShell? Properties windows don't refresh dynamically. They only show the state of things from when they first opened. – Aaron Jensen Aug 01 '13 at 19:16
  • @splatteredbits, yes I've closed it and opened it a hundred times... Lol... Are these two different properties that I'm working with? – BlackHatSamurai Aug 01 '13 at 19:18
  • 1
    No. They are the same property. I did some testing on my computer and setting the `IsReadOnly` flag to false unchecks the checkbox on the Properties window. Check that your PowerShell script is modifying the file you think it is. I've spent hours before wondering why something wasn't working until I realized I was looking at the wrong file. – Aaron Jensen Aug 01 '13 at 19:21
  • FML... You were exactly right. I was working on the wrong file. God, I feel like an idiot. Thank you for your help. – BlackHatSamurai Aug 01 '13 at 19:25
  • 1
    I was about to say - that screenshot shows you haven't changed the file since 2 days ago... – latkin Aug 01 '13 at 19:26

2 Answers2

10

This works:

Get-Item -Path "path/to/my/file.dat" |
    Set-ItemProperty -Name IsReadOnly -Value $false
Aaron Jensen
  • 25,861
  • 15
  • 82
  • 91
5

You can actually skip the first line:

$file = Get-Item "path/to/my/file.dat"
Set-ItemProperty $file -Name IsReadOnly -Value $false
Dreami
  • 311
  • 1
  • 5