How do I change a file's attribute using Powershell?

后端 未结 6 1702
抹茶落季
抹茶落季 2021-02-05 05:07

I have a Powershell script that copies files from one location to another. Once the copy is complete I want to clear the Archive attribute on the files in the source location t

6条回答
  •  难免孤独
    2021-02-05 05:22

    As the Attributes is basically a bitmask field, you need to be sure clear the archive field while leaving the rest alone:

    PS C:\> $f = get-item C:\Archives.pst
    PS C:\> $f.Attributes
    Archive, NotContentIndexed
    PS C:\> $f.Attributes = $f.Attributes -band (-bnot [System.IO.FileAttributes]::Archive)
    PS C:\> $f.Attributes
    NotContentIndexed
    PS H:\>
    

提交回复
热议问题