How to retrieve files and folders attributes using PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

To retrieve files and folders attributes using PowerShell, you can use Get-Item or Get-ChildItem command. For example, We have a file called testfile.txt to get its attributes,

PS C:\> Get-ChildItem C:\Temp\TestFile.txt |Select Name,Attributes
Name          Attributes
----          ----------
TestFile.txt  Archive

So this file has the Archive attribute. To retrieve multiple files and folders' attributes, just refer to the folder name instead of the file name.

Get-ChildItem C:\Temp -Recurse -Force | Select Name, FullName, Attributes
Name          Attributes
----          ----------
TestFile.txt  Archive

-Force parameter will retrieve all the files and folders including Hidden and read-only.

The above same thing can be achieved with the Get-Item command.

Get-Item C:\Temp\TestFile.txt |Select Name,Attributes
raja
Published on 16-Oct-2020 12:49:19
Advertisements