如何使用PowerShell (1.0版)脚本删除文件的ReadOnly属性?
发布于 2009-05-21 23:57:08
您可以使用Set-ItemProperty
Set-ItemProperty file.txt -name IsReadOnly -value $false或更短:
sp file.txt IsReadOnly $false发布于 2009-05-21 14:22:53
$file = Get-Item "C:\Temp\Test.txt"
if ($file.attributes -band [system.IO.FileAttributes]::ReadOnly)
{
$file.attributes = $file.attributes -bxor [system.IO.FileAttributes]::ReadOnly
} 上面的代码片段取自这个article
从注释中使用Keith Hill's实现更新(我已经测试过了,它确实有效),这变成了:
$file = Get-Item "C:\Temp\Test.txt"
if ($file.IsReadOnly -eq $true)
{
$file.IsReadOnly = $false
} 发布于 2009-05-22 15:49:21
即使它不是原生PowerShell,也可以使用简单的Attrib命令来实现:
attrib -R file.txthttps://stackoverflow.com/questions/893167
复制相似问题