Posts

Showing posts from April, 2014

Monitoring rotating text files in real time with Powershell

So I needed a way to monitor some log files in a folder where a new log file gets created when the current one gets too large. All I'm interested in is checking the latest one for certain strings and then alerting if they occur.

Powershell to the rescue:


#folder to be watched $folder = 'C:\Temp\logger' #file types to be watched for $filter = '*.log' # <-- set this according to your requirements #strings to find in log $matchstring="My matching string" #variable to hold background powershell job $catjob #start a cat task as background process Function StartCat ($filepath) { #stop job is already monitoring a file if ($Global:catjob -ne $null) { stop-job -job $catjob remove-job -job $catjob } $scriptblock = { param ($file, $matchstring) cat $file -wait | ?{$_ -match $matchstring} } #start new job when file changed $Global:catjob = start-jo…

Wildcard Subdomains in Windows DNS

On a test web server you may have the need to host multiple websites under several subdomains:

site1.server.domain.local
site2.server.domain.local
site3.server.domain.local

Setting up the host headers is straightforward, but a bit of work is required in Windows DNS to get the subdomains working correctly.


Launch DNS consoleExpand Forward Lookup ZonesRight click on your domain and click "New Domain"Enter the name of your server (if that's what you're using as the top level of the sub domain)Right click the new domain and click "New Host (A or AAAA)"Enter "*" (without the quotes) for the name and then the IP address of your serverClick OKOn the server in a raised cmd prompt: ipconfig /flushdnsipconfig /registerdnsAll done and your your subdomains will be resolved.

Cleaning up Sharepoint 2013 backups

Sharepoint is pretty horrible when it comes to backups, but presuming that you're doing Farm backups rather than just your content database, you'll have to deal with them.

I do one full backup per week and differentials in between from Task Scheduler. This generates a lot of data that needs cleaning up, so here's a bit of script. Most of this is directly lifted from a script by Meat Head Nerd which I changed to look at the full backups rather than just age of backup.

This will remove all full and differential backups prior to the number of full backups you want to keep.


# Number of full back ups you want to keep $numfullbackups = 1 # Import the Sharepoint backup report xml file $spbrtoc = “c:\temp\spbrtoc.xml” [xml]$sp = gc $spbrtoc # Find the full backups in spbrtoc.xml $fullbackups = $sp.SPBackupRestoreHistory.SPHistoryObject | ? { $_.SPBackupMethod -eq 'Full' } # Get the start time of the last full backup $lastfullstarttime = $fullbackups…