childebrandt42

Worthless info……………Oh blinky lights!

Horizon View Persona Management Duplicate AppData LOC folders

Posted by

·

,

I don’t know if anyone out there has had issues with Horizon View 6 with Persona Management and Duplicate AppData LOC folders like DualAppDatathis one here in the picture. As you can see the one on top is a current LOC folder. But the one on the bottom has an older date. When you get duplicates of these folders (Really don’t know the appropriate name for them) some ugly issues arise. I guess I should go into detail on how these are made. When your Horizon View user logs into their desktop the user profile is copied to the desktop. When this process is started this folder like {08C31585-259A-4341-9982-78E42EAF6106} is created. This is a placeholder for when the user logs off to sync the data back to the Person Management store. And when the user logs in the next day all their previous changes are on the desktop as you would expect. When you have a old LOC folder (For lack of a better term that is what I am going to call it) and a current one, The old one is considered the active placeholder for a sync, problem is that sync failed for some reason. With the old LOC folder being there it is blocking all changes from any new sync attempts. So any changes after that old LOC folder was created nothing was ever saved. They were just flushed away and a new lock started the next day. I have found no way to fix this and with VMware it’s a known issue with no real fix yet. The only way I have found to get the users to start saving data again is to delete the old LOC folder and have the user logout and back in. And from that point on the changes will be saved.

I have not found a good way to stop this from happening, or a good way to detect them till a few days ago. I managed to create a Powershell script that creates a report of the old LOC folders in your Persona repository and emails the report to you. If you choose you can enable the Delete function so when it runs the report it will go through and find all the old LOC folders and add them to the report and then delete the folders. So when the report is emailed to you it’s a deleted folder log.

Report

This is an example of what the report would send you. Full file location, Last Write Time and Creation Time. If you remove the comment from Line 134 in the script it will enable the delete function and remove those folders as it is ran.

#remove-item $exdata[$alternateTableRowBackground].FullName -Confirm:$false -ErrorAction SilentlyContinue -Force -Recurse

<#
.SYNOPSIS
 

.DESCRIPTION
 The purpose of this script is to find old AppData LOC folders in the root user directory and optional delete the folders for you. This will create a report of all the folders matching the search 
 older than Today's date. And if you enable the delete function it will delete the folders also. And the report would be the delete log. 

 Author:Chris Hildebrandt @childebrandt42
 Last Modified: 10/19/2015

.Version
 1.2
#>

#----------------------------------------------------------------------------------------------------------------------------------------------------
#Variables to configure

$MailServer = "Email Server IP address or DNS "
$ReportSender = "Who you want the email to be sent from"
$ReportRecipient = "who you want the email to go to. Comma separated no spaces (Ex test@email.com,test2@email.com"

#Change the mail subject if you like
$MailSubject = ("VMware duplicate AppData LOC Folder Report - " + (get-date).ToString('yyyy/MM/dd'))

#Folder path is the path of your Horizon View Persona Profile Repository
$folderPath = "C:\Test\*" 
#Search info. Don't change this option. This will search for the folders names like {08C31585-259A-4341-9982-78E42EAF6106} in the User root folder.
$folderName = "{*}"

#There is one more variable to change if you like. On line 134 there is a Remove-Item command that is commented out. 
#This will remove all the Duplicate AppData LOC folders that are are not current. 
#----------------------------------------------------------------------------------------------------------------------------------------------------

#Add Exchange 2010 snapin if not already loaded
if (!(Get-PSSnapin | where {$_.Name -eq "Microsoft.Exchange.Management.PowerShell.E2010"}))
{
 Write-Verbose "Loading the Exchange 2010 snapin"
 try
 {
 Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction STOP
 }
 catch
 {
 #Snapin not loaded
 Write-Warning $_.Exception.Message
 EXIT
 }
 . $env:ExchangeInstallPath\bin\RemoteExchange.ps1
 Connect-ExchangeServer -auto -AllowClobber
}


#SendEmailFunction
Function sendEmail
{ param($smtphost,$htmlFileName)
$smtp= New-Object System.Net.Mail.SmtpClient $smtphost
$msg = New-Object System.Net.Mail.MailMessage $ReportSender, $ReportRecipient, $MailSubject, (Get-Content $htmlFileName)
$msg.isBodyhtml = $true
$smtp.send($msg)
}

$exdata = Get-ChildItem -Force $folderPath\* -ErrorAction SilentlyContinue | Where-Object { ($_.PSIsContainer -eq $true) -and ( $_.Name -like "*$folderName*") } | Select-Object FullName,lastwritetime,CreationTime 

$fileName = "ViewPersonaReport.html"
New-Item -ItemType file $fileName -Force

# HTML start
Add-Content $fileName "<html>"

# HEAD start
Add-Content $fileName "<head>"

add-content $fileName '<STYLE TYPE="text/css">'
add-content $fileName "<!--"
add-content $fileName "td {"
add-content $fileName "font-family: Tahoma;"
add-content $fileName "font-size: 11px;"
add-content $fileName "border-top: 1px solid #999999;"
add-content $fileName "border-right: 1px solid #999999;"
add-content $fileName "border-bottom: 1px solid #999999;"
add-content $fileName "border-left: 1px solid #999999;"
add-content $fileName "padding-top: 0px;"
add-content $fileName "padding-right: 0px;"
add-content $fileName "padding-bottom: 0px;"
add-content $fileName "padding-left: 0px;"
add-content $fileName "}"
add-content $fileName "body {"
add-content $fileName "margin-left: 5px;"
add-content $fileName "margin-top: 5px;"
add-content $fileName "margin-right: 0px;"
add-content $fileName "margin-bottom: 10px;"
add-content $fileName ""
add-content $fileName "table {"
add-content $fileName "border: thin solid #000000;"
add-content $fileName "}"
add-content $fileName "-->"
add-content $fileName "</style>"

# HEAD end
Add-Content $fileName "</head>"

# HEAD start
Add-Content $fileName "<body>"

# TABLE start
Add-Content $fileName "<table width='100%'>"

# TABLE Header
Add-Content $fileName "<tr bgcolor='#7C7C7C'>"
Add-Content $fileName "<td width='80%'>FullName</td>"
Add-Content $fileName "<td width='10%'>lastwritetime</td>"
Add-Content $fileName "<td width='10%'>CreationTime</td>"
Add-Content $fileName "</tr>"

$alternateTableRowBackground = 0

# TABLE Content
while($alternateTableRowBackground -le $exdata.length)
{
if(($alternateTableRowBackground % 2) -eq 0)
{
Add-Content $fileName "<tr bgcolor='#CCCCCC'>"
}
else
{
Add-Content $fileName "<tr bgcolor='#FCFCFC'>"
} 

#FullName Old Folder Red
if($exdata[$alternateTableRowBackground].CreationTime -lt (get-date).ToShortDateString())
{
Add-Content $fileName ("<td bgcolor='#FF0000' width='80%'>" + $exdata[$alternateTableRowBackground].FullName + "</td>")
#remove-item $exdata[$alternateTableRowBackground].FullName -Confirm:$false -ErrorAction SilentlyContinue -Force -Recurse
}

#LastwriteTime Old Folder Red
if($exdata[$alternateTableRowBackground].CreationTime -lt (get-date).ToShortDateString())
{
Add-Content $fileName ("<td bgcolor='#FF0000' width='10%'>" + $exdata[$alternateTableRowBackground].lastwritetime + "</td>")
}

#Creation Time Comparison Old Folder Red
if($exdata[$alternateTableRowBackground].CreationTime -lt (get-date).ToShortDateString())
{
Add-Content $fileName ("<td bgcolor='#FF0000' width='10%'>" + $exdata[$alternateTableRowBackground].CreationTime + "</td>")
}

Add-Content $fileName "</tr>"

$alternateTableRowBackground = $alternateTableRowBackground + 1
}

#TABLE end
Add-Content $fileName "</table>"

# HEAD end
Add-Content $fileName "</body>"

# HTML end
Add-Content $fileName "</html>"

sendEmail $MailServer $fileName

Thank you to Jon Hildebrand @snoopj123 and David Daniels @putinexim for pointing me in the right direction and not giving me the answers in my powershell questions.

Edited#

I decided to change the version on this a bit. I decided to add the function to only send the HTML report when there was a folder older than a day. I added a If statement with the sendemail function.

I also removed the load the exchange snapin.

I did learn something while doing this. Never underestimate the power of RoboCopy. It took me a day to test this as I created the files to test with and waited for the next day to test, and when I came in the next morning I had one of those eye opening events and remembered about RoboCopy it will copy folder creation dates. I ran RoboCopy to copy some other folders to make sure I had plenty of data to test on.

Lesson: Never Underestimate the Power of RoboCopy!

<#
.SYNOPSIS
 

.DESCRIPTION
 The purpose of this script is to find old AppData LOC folders in the root user directory and optional delete the folders for you. This will create a report of all the folders matching the search 
 older than Today's date. And if you enable the delete function it will delete the folders also. And the report would be the delete log. 

 Author:Chris Hildebrandt @childebrandt42
 Last Modified: 11/5/2015

.Version
 1.5
#>

#----------------------------------------------------------------------------------------------------------------------------------------------------
#Variables to configure

$MailServer = "Email Server IP address or DNS "
$ReportSender = "Who you want the email to be sent from"
$ReportRecipient = "who you want the email to go to. Comma separated no spaces (Ex test@email.com,test2@email.com"

#Change the mail subject if you like
$MailSubject = ("VMware duplicate AppData LOC Folder Report - " + (get-date).ToString('yyyy/MM/dd'))

#Folder path is the path of your Horizon View Persona Profile Repository
$folderPath = "C:\Test\*" 
#Search info. Don't change this option. This will search for the folders names like {08C31585-259A-4341-9982-78E42EAF6106} in the User root folder.
$folderName = "{*}"

#There is one more variable to change if you like. On line 134 there is a Remove-Item command that is commented out. 
#This will remove all the Duplicate AppData LOC folders that are are not current. 
#----------------------------------------------------------------------------------------------------------------------------------------------------

#SendEmailFunction
Function sendEmail
{ param($smtphost,$htmlFileName)
$smtp= New-Object System.Net.Mail.SmtpClient $smtphost
$msg = New-Object System.Net.Mail.MailMessage $ReportSender, $ReportRecipient, $MailSubject, (Get-Content $htmlFileName)
$msg.isBodyhtml = $true
$smtp.send($msg)
}

$exdata = Get-ChildItem -Force $folderPath\* -ErrorAction SilentlyContinue | Where-Object { ($_.PSIsContainer -eq $true) -and ( $_.Name -like "*$folderName*") } | Select-Object FullName,lastwritetime,CreationTime 

$fileName = "ViewPersonaReport.html"
New-Item -ItemType file $fileName -Force

# HTML start
Add-Content $fileName "<html>"

# HEAD start
Add-Content $fileName "<head>"

add-content $fileName '<STYLE TYPE="text/css">'
add-content $fileName "<!--"
add-content $fileName "td {"
add-content $fileName "font-family: Tahoma;"
add-content $fileName "font-size: 11px;"
add-content $fileName "border-top: 1px solid #999999;"
add-content $fileName "border-right: 1px solid #999999;"
add-content $fileName "border-bottom: 1px solid #999999;"
add-content $fileName "border-left: 1px solid #999999;"
add-content $fileName "padding-top: 0px;"
add-content $fileName "padding-right: 0px;"
add-content $fileName "padding-bottom: 0px;"
add-content $fileName "padding-left: 0px;"
add-content $fileName "}"
add-content $fileName "body {"
add-content $fileName "margin-left: 5px;"
add-content $fileName "margin-top: 5px;"
add-content $fileName "margin-right: 0px;"
add-content $fileName "margin-bottom: 10px;"
add-content $fileName ""
add-content $fileName "table {"
add-content $fileName "border: thin solid #000000;"
add-content $fileName "}"
add-content $fileName "-->"
add-content $fileName "</style>"

# HEAD end
Add-Content $fileName "</head>"

# HEAD start
Add-Content $fileName "<body>"

# TABLE start
Add-Content $fileName "<table width='100%'>"

# TABLE Header
Add-Content $fileName "<tr bgcolor='#7C7C7C'>"
Add-Content $fileName "<td width='80%'>FullName</td>"
Add-Content $fileName "<td width='10%'>lastwritetime</td>"
Add-Content $fileName "<td width='10%'>CreationTime</td>"
Add-Content $fileName "</tr>"

$alternateTableRowBackground = 0

# TABLE Content
while($alternateTableRowBackground -le $exdata.length)
{
if(($alternateTableRowBackground % 2) -eq 0)
{
Add-Content $fileName "<tr bgcolor='#CCCCCC'>"
}
else
{
Add-Content $fileName "<tr bgcolor='#FCFCFC'>"
} 

#FullName Old Folder Red
if($exdata[$alternateTableRowBackground].CreationTime -lt (get-date).ToShortDateString())
{
Add-Content $fileName ("<td bgcolor='#FF0000' width='80%'>" + $exdata[$alternateTableRowBackground].FullName + "</td>")
#remove-item $exdata[$alternateTableRowBackground].FullName -Confirm:$false -ErrorAction SilentlyContinue -Force -Recurse
}

#LastwriteTime Old Folder Red
if($exdata[$alternateTableRowBackground].CreationTime -lt (get-date).ToShortDateString())
{
Add-Content $fileName ("<td bgcolor='#FF0000' width='10%'>" + $exdata[$alternateTableRowBackground].lastwritetime + "</td>")
}

#Creation Time Comparison Old Folder Red
if($exdata[$alternateTableRowBackground].CreationTime -lt (get-date).ToShortDateString())
{
Add-Content $fileName ("<td bgcolor='#FF0000' width='10%'>" + $exdata[$alternateTableRowBackground].CreationTime + "</td>")
}

Add-Content $fileName "</tr>"

$alternateTableRowBackground = $alternateTableRowBackground + 1
}

#TABLE end
Add-Content $fileName "</table>"

# HEAD end
Add-Content $fileName "</body>"

# HTML end
Add-Content $fileName "</html>"

#Only Send email if there is a folder older than today
if($exdata[$alternateTableRowBackground].CreationTime -lt (get-date).ToShortDateString())
{
sendEmail $MailServer $fileName
}
childebrandt42 Avatar

About the author

Hi! My name is Chris Hildebrandt, I’m a EUC consultant by day, and automation junkie at night. I have worked my way from being small customer to enterprise side customer, with a recent transition into consulting. I enjoy everything EUC focused and more so on how to automate it. I like to find ways to make mine and your jobs easier with automation.