Synopsis: Some PowerShell to fix file permissions on Citrix UPM
Yes, I'm aware that FSLogix is the new kid on the block. It's even not that new anymore. Microsoft snapped it up at the end of 2018. Yes, that long ago already.
That does not mean everybody is using it by now. Take Citrix User Profile Management (Citrix UPM). There are (many?) cases where that's just good enough to get the job done. Or people just don't bother to replace it really.
As you might recall from a previous blogpost , I have been running some migration scripts 24/7. The crucial part of those scripts is getting the correct files over from the old system to the new. To be more precise: from the old Citrix UPM share to the new. Those can contain QlikView favourites and what have you.
Once you located the files that hold the information you're after, your set. You can copy those files over. It's a file share, in the end, so that shouldn't be that difficult.
And yes, you can just copy those files. The files will be there. Chances are, however, they are useless. Why? There's a "little" catch. If the file you are copying does not yet exist on the target Citrix UPM share, it will still get copied, but... the file permissions are off. And a file that you can't access is of no use for the application. It can even cause the profile to become corrupted, if you're not careful.
Fixing those permissions proved to be quite a bit trickier than I first imagined. It took some tweaking to get it right. The magic is running two commands:
icacls $PathToFile /setowner $User.samaccountname
icacls $PathToFile /inheritancelevel:e
After that, permissions are fixed, and your files are ready to go. Your users will thank you for all the application settings you were able to recover for them.
I marked this post as part of my ToolBox, so there's a little bit of code on GitHub here to go with this post. It's a basic version of a script that I have used to copy SAP NBWC settings from one account to another. It's very basic, with no checks for running sessions for example. Consider it a base version you'll need to work on a bit to make it safe.