This small powershell script checks if a given file is read-only or not.
$status = Get-ChildItem c:temptest.txt
If ($status.isreadonly)
{
Write-host -b yellow -f red “The file, $status.fullname is a read-only file”
}
Else
{
Write-host -b yellow -f red “The file, $status.fullname is a read-only file”
}
If you want to make a file as readonly, use the below code
$status = Get-ChildItem c:temptest.txt
$status.set_isreadonly($true)
If ($status.isreadonly)
{
Write-host -b yellow -f red “The file, $status.fullname is a read-only file”
}
Else
{
Write-host -b yellow -f red “The file, $status.fullname is a read-only file”
}
If you want to remove the read-only a ttribute just change the parameter of set_isreadonly method to $false.
Happy Learning,
Sitaram Pamarthi
Comments on this entry are closed.
Wrong command: set_isreadyonly, should be set_isreadonly.
I corrected. It’s a typo