I came across another opportunity for using Powershell when setting up mirroring for a large database at our DR site. The database was over 73Gig. The problem arose when it took a very long time to copy the backup and transaction logs and run the database restore. By the time the copy had finished another several transaction logs had been produced. While applying the *.bak restore, yet another several transaction logs had been produced. Continue reading ‘Restore All SQL Transaction Logs using Powershell’ »
Posts tagged ‘tips’
This is a wonderful article which not only details the use of Compare-Object but also provides some very excellent examples on its use.
Tips & Tricks Using Compare-Object – Dreaming in PowerShell – PowerShell.com
I am very new to PowerShell but I am beginning to like using it considerably more each day. I recently had a need for a quick and easy way to script a process which would copy only new files from one location to another. after scouring the Internet for a good example, I stumbled upon the Compare-Object cmdlet and this excellent article.
The actual script I came up with is rather simple and serves my purpose exactly. As I mentioned, I am new to PowerShell and there may very well be a better method. However, this one works for me.
The script code:
param(
[string]$s = '\\serverx\c$\ProgramData\Polaris\3.5\SQLVS1\AuthorityUpdates',
[string]$t = '\\servery\data03\shared\libraries\zmarc'
)
$target = Get-ChildItem $t
$source = get-childitem $s
Compare-Object $source $target -Property Name -PassThru |
Where-Object { $_.SideIndicator -eq '<=' } |
foreach-object -process{
copy-item $_.FullName -destination $t
}