PowerShell Script To Find Folder Redirection Errors

If you work in large organisations it’s common to have home directories in a lot of different locations and a lot of different folder redirection policies.

Over time, if not maintained, you can end up with a lot of errors in your folder redirection policy.

This script will pull the last 30 days worth of folder redirection errors from the event logs of all the XenApp servers in your farm.

It will work for both Windows 2003 and Windows 2008.

Disclaimer: Depending on the size of your farm this could take quite a while to run and could impact your servers and / or network.

[code lang=”powershell”]

#*FileName: XenApp_Folder_Redirection_Errors.ps1

#*=========================================

#*Created 03/04/2013

#*Author: Shaun Ritchie

#*www.shaunritchie.co.uk

#*

#*

#*

#*=========================================

#*

#*

#*

#*=========================================

#* SCRIPT BODY

#*=========================================

add-pssnapin Citrix.* -erroraction silentlycontinue

$servers = Get-XAServer
$date = (get-date).AddDays(-30)

#Get eventlogs from each XenApp server
$events = foreach ($server in $servers){
get-eventlog -LogName Application -ComputerName $server.ServerName -After $date
}

# Match all events relating to Folder Redirection Errors. This catches W2k03 and W2k08 event log entries
$events = $events | where-object {$_.Source -like “*Folder Redirection*” -and $_.EntryType -eq “Error” } | select-object @{Name=’UserName’; Expression={$_.Username}}, @{Name=’message’; Expression={$_.Message}} -unique

$outpath = [environment]::getfolderpath(“mydocuments”) + “XenApp_Folder_Redirection_Errors.csv”

$events | Export-CSV $outpath Write-Host “File has been saved to” $outpath
[/code]

Comments

Be the first to comment!

Join the discussion