How to Change File Properties (ReadOnly, CreationTime etc.) Using PowerShell

Changing file properties is quite easy with PowerShell.


Remove ReadOnly attribute:

Set-ItemProperty -Path 'C:\Program Files\desktop.ini' -Name IsReadOnly -Value $false


Change CreationTime (90 days back in time):

Set-ItemProperty -Path 'C:\Program Files\desktop.ini' -Name CreationTime -Value ((Get-Date).AddDays(-90))




Handling attributes with hyphens in PowerShell

Sometimes we need working with PowerShell objects which have attributes with hyphens. That can be a bit difficult as PowerShell assumes hyphens are used with operators and parameters.

Below is an example on how to get around this, and rename the attribute:



$Users = Get-AdUser -Filter * -Property "msDS-ResultantPSO" | Select name, @{Name="ResultantPSO";Expression={$_."msDS-ResultantPSO"}}