# 添加只读属性- (Get-Item 1.txt).IsReadOnly = $true
复制代码 # 删除只读属性- (Get-Item 1.txt).IsReadOnly = $false
复制代码 # 添加隐藏属性- $file=(Get-Item 1.txt)
- $AttrOld = $file.Attributes
- $file.Attributes = $AttrOld, "Hidden"
- $file.Attributes
复制代码 # 删除隐藏属性- $file=(Get-Item -Force 1.txt)
- $file.Attributes = $file.Attributes -bxor [System.IO.FileAttributes]::Hidden
- $file.Attributes
复制代码 # 删除只读、隐藏等属性,只保留正常属性- $file=(Get-Item -Force 1.txt)
- $file.Attributes = $file.Attributes -bxor [System.IO.FileAttributes]::Hidden
- $file.Attributes
复制代码 # 属性列表
- ReadOnly
- Hidden
- System
- Directory
- Archive
- Device
- Normal
- Temporary
- SparseFile
- ReparsePoint
- Compressed
- Offline
- NotContentIndexed
- Encrypted
- IntegrityStream
- NoScrubData
# 查看文件创建时间、修改时间- $file=(Get-Item 1.txt)
- Get-Date $file.CreationTime -UFormat "%Y-%m-%d %H:%M:%S"
- Get-Date $file.LastAccessTime -UFormat "%Y-%m-%d %H:%M:%S"
- Get-Date $file.LastWriteTime -UFormat "%Y-%m-%d %H:%M:%S"
复制代码 # 修改文件创建时间、修改时间- $file=(Get-Item 1.txt)
- $file.CreationTime = (Get-Date).AddDays(-1)
- $file.LastWriteTime = (Get-Date).AddDays(-1)
- Get-Date $file.CreationTime -UFormat "%Y-%m-%d %H:%M:%S"
- Get-Date $file.LastWriteTime -UFormat "%Y-%m-%d %H:%M:%S"
复制代码
|