PowerShell: change TimeStamp of files on Windows Servers

So here we go: last post of 2013. First one about this great little tool: Powershell. It’s not directly related to databases, though. But this tool is reaching a mature state and it is so usefull for SQL Server administration that any tuned DBA can not give up on learning it.

Today I needed to compact an old .BAK file, but keep the original file creation/modify/access time. This little script came to help. It works for any file, but I’m not interested in other things. Only database files matter to me 🙂

So here it is, quoted from the above link. There is a lot of material about advanced scripts for PowerShell, but we it’s easier start from somewhere simple and small. This sequence of commands will create an “object” with the information from your file, and then you can edit it’s properties using PS functions just like you were programing something.

1- Open PowerShell and go to desired folder
2- run the commands:
PS> $a = Get-Item file.zip
PS> $a.LastWriteTime = “mm/dd/aaaa hh:mm:ss”
PS> $a.LastAccessTime = “mm/dd/aaaa hh:mm:ss”
PS> $a.CreationTime = “mm/dd/aaaa hh:mm:ss”
3 – close PS

And that’s it. Over the next year I’m planing more posts on Oracle and MongoDB. If the tides are good, I will post a series of scripts to create an auditing structure over dissimilar databases. Have a nice Xmas and cya next year!

Advertisements

About mauriciorpp

Hi, I am Piccolo - but not the one from Dragon Ball. I'm from a highly competitive and fast-paced world too, the IT industry, and this space will be used to share some challenges I face daily on my career. As you will see, I don't do brawls but I need to be a fighter! Stay tuned.
This entry was posted in Windows and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s