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!