All Versions
.NET objects often have properties that you can read to retrieve information. Some of these properties may actually be writeable, so you can use them to change the object.
To find writeable properties, here is a trick. Take any .NET object, and pipe it to Get-Member like so:
# get an object to play with $file = Get-Item -Path C:\WINDOWS\explorer.exe # find all settable properties $file | Get-Member -MemberType *method -Force -Name 'set_*' | ForEach-Object { $_.Name.Substring(4) }
For files, it turns out all of these properties are writeable:
Attributes CreationTime CreationTimeUtc IsReadOnly LastAccessTime LastAccessTimeUtc LastWriteTime LastWriteTimeUtc
Simply assign new values to these properties to change the file object.