Working with PowerShell is usually a serious and demanding job. PowerShell is powerful, you can destroy your system by running the wrong commands. However, in this blog post we take a look at something funny. But it’s possible that what we’re about to do you might need for something serious. Now let’s start. We are going to change the creation time of a file or folder. With PowerShell, what else?
PowerShell Attributes and Methods
As already mentioned in my series PowerShell for Beginners, Attributes show what an object is and methods let us do something with objects.
The Power of PowerShell is object-orientation. This is what distinguishes PowerShell from many other tools. You have to deal with Objects. Otherwise you will never realize the power of PowerShell.
And further …
Attributes show you what an Object is. Methods can change or do something.
More about Attributes and Methods here:
Ok, let’s start. We are going to try changing the creation time of a file.
Changing the Creation Time of a File with the .NET Method
C:\Temp\Test.txt ist a simple text file. It was created on July 13th 2019. This is our starting point.
Changing the creation time means working with PowerShell methods. While running Get-ChildItem along with Get-Member we discover that there is an attribut called CreationTime.
Get-ChildItem -Path C:\Temp\Test.txt | Get-Member -MemberType Properties
Finally, we call a .NET method to change the creation time to July 7th, 1643.
(Get-ChildItem -Path C:\Temp\Test.txt).CreationTime='07.07.1643'
Nice one! We’re done. Check out your changes in Windows Explorer and/or PowerShell.
Get-ChildItem -Path C:\Temp\Test.txt | Select-Object -Property CreationTime
See you next time with Powershell and doing more serious stuff!