$Path|Set-ItemProperty -name Hidden -Value $true
$Path|Set-ItemProperty -name isHidden -Value $true
Set-ItemProperty -path $Path -name isHidden -Value $true
#Error: Set-ItemProperty: The property bool isHidden=False does not exist or was not found.
There is no argument completion for -name property, so its hard to tell what it supports or not. I know how to lock a file with it, only because it is one of the examples in the docs:
$Path|Set-ItemProperty -name IsReadOnly -Value $true
Any help would be greatly appreciated!
Santiago's helpful answer provides an effective solution that relies on direct use of .NET type members.
An even simpler solution is to use the standard
attrib.exeutility, whose sole purpose is to manage file attributes:As for using
Set-ItemProperty:On Windows,[1] it is the
Attributesproperty that you need to target, and whileSet-ItemProperty -Path $Path -Name Attributes -Value Hiddendoes work in principle, the caveat is:The
-Valueargument invariably fully replaces the existing attributes, so that you'd need to make sure to also include any preexisting attributes in order to preserve them if your intent is to selectively set attributes:[2]E.g., if the target item has the
Archiveattribute set, and you needed to preserve that, you'd need to specify-Value 'Hidden, Archive'.That is, you'd need to specify a single string containing a
,-separated list of the symbolic names ofSystem.IO.FileAttributesenumeration values, relying on PowerShell's convenient to-and-from-string conversion ofSystem.Enum-derived types.(The cumbersome type-exact equivalent of the above would be:
-Value ([System.IO.FileAttributes]::Hidden -bor [System.IO.FileAttributes]::Archive))Thus, in order to clear all attributes (that can be cleared), pass
-Value 'None'Operating on the
.Attributesproperty ofSystem.IO.FileSystemInfoinstances, as output byGet-ItemorGet-ChildItem, makes basing the updated value on the existing attributes easier, as shown in Santiago's answer.[1] On Unix-like platforms, visibility is determined simply by an item's (file or directory's) name: if the name starts with
., the item is considered to be hidden. macOS, specifically, supports an additional mechanism for hiding items, via extended file-system attributes.[2] The
Directoryattribute is special, however: it is invariably set for directories and cannot be cleared.