Change a file marked as system

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Dave Wyatt Dave Wyatt 2 years, 1 month ago.

  • Author
    Posts
  • #19757
    Profile photo of Tony Wainwright
    Tony Wainwright
    Participant

    Hi
    I'm trying to change the attribute of a file called folder.jpg from System/Hidden to Normal.

    I am using this code:

    $SFile = Get-ChildItem folder.jpg -System -Force
    $SFile.Attributes = 'Normal'

    but I get the following error[blockquote]The property 'Attributes' cannot be found on this object. Verify that the property exists and can
    be set.
    At line:1 char:1
    + $File.Attributes = 'Normal'
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound[/blockquote]
    Is there something wrong with what I've done
    Thanks
    Tony

  • #19758
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    Hard to tell from what I can see here. What do you get if you run $File.GetType().FullName?

  • #19760
    Profile photo of Tony Wainwright
    Tony Wainwright
    Participant

    Hi Dave

    $[b][u]S[/u][/b]File.GetType().FullName returns System.IO.FileInfo

  • #19761
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    The error message you posted mentions a variable named $File, not $SFile:

    The property 'Attributes' cannot be found on this object. Verify that the property exists and can
     be set.
     At line:1 char:1
     + $File.Attributes = 'Normal'
     + ~~~~~~~~~~~~~~~~~~~~~~~~~~~
     + CategoryInfo : InvalidOperation: (:) [], RuntimeException
     + FullyQualifiedErrorId : PropertyNotFound
    

    If you've got two different variables / objects involved here (or if $file just doesn't exist), that could be the problem.

You must be logged in to reply to this topic.