Posts Categorized: powershell

Powershell Script to Set Computer Name Based on DNS

This Powershell script will use nslookup to query a DNS Server to get the hostname and use that result to set the computer name. If you use this you will need to amend as necessary including the address of the DNS Server (I have added the Google one here for illustration) and I am filtering… Read more »

Nagios Check for Windows Updates


My colleagues have been getting a little frustrated by the “Plugin Timeout” messages in Nagios resulting from the length of time it takes to check for Windows Updates. I had been using Jules Check for Windows Updates  that essentially boils down to calling:

So I took Jules’ work and divided the powershell script into… Read more »

Removing Old IIS Logs

Simple powershell script to remove old IIS logs (or any other file for that matter). $pathToLogs = “C:\WINDOWS\system32\LogFiles\W3SVC1”;$LogAgeTarget = 183; # Number of days of logs to keep$dteNow = Get-Date     if (Test-Path $pathToLogs){      $LastWrite = $Now.AddDays(-$LogAgeTarget)      $Files = Get-ChildItem $pathToLogs -include *.log -recurse |            Where {$_.LastWriteTime -le “$LastWrite”}      … Read more »

Exchange 2007 Logs from Client Access Machines

A short script to make it a little easier to retrieve logs from several client access machines. A little quicker than using the Toolbox Message Tracking Log: $strEvent = “RECEIVE”$dteStart = “31/08/2008 12:34:00”$dteEnd = “01/09/2008 16:44:00”$strMessageSubject = “Email Account Owner”Get-ExchangeServer Where {$_.ServerRole -match ‘ClientAccess’} ForEach {Get-MessageTrackingLog -Server $_.Fqdn -EventID $strEvent -MessageSubject $strMessageSubject -Start $dteStart -End… Read more »

Add Exchange Snapin to Windows Powershell

Trying to run exchange-specific commands in the windows powershell returns errors so to make the windows powershell aware of the exchange commands we need to add the appropriate snap in with: Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin That line can be added at the top of any scheduled task powershell scheduled tasksimport use exchange commands in windows powershelladd… Read more »

Beginning Powershell

When writing my first powershell script to check free disk space on a dozen exchange servers I picked up a few useful things for future reference. Echoing output to the command lineA script can print/write output to stdout using Write-Host “Hello World” but this command is aliased too, so that echo “Hello World” will also… Read more »