如何使用 PowerShell 檢索檔案和資料夾屬性?


若要使用 PowerShell 檢索檔案和資料夾屬性,可以使用 Get-ItemGet-ChildItem 命令。例如,我們有一個名為 testfile.txt 的檔案,若要獲取其屬性,

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

因此,此檔案具有存檔屬性。若要檢索多個檔案和資料夾的屬性,只需引用資料夾名稱,而不引用檔名即可。

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

-Force 引數將檢索所有檔案和資料夾,包括 Hiddenread-only

同樣的事情可以使用 Get-Item 命令來實現。

Get-Item C:\Temp\TestFile.txt |Select Name,Attributes

更新於: 16-Oct-2020

3000+ 瀏覽量

開啟 職業生涯

透過完成課程獲得認證

開始
廣告