When using Microsoft User Profile Disks you also know the tool Sidder: https://gallery.technet.microsoft.com/Sidder-Quickly-see-which-fa6360b3
This tool will show the username who belongs the the User Profile Disk.
I’ve found this not so conveniant as you must run it every time you want to know the username.
So I dusted off my powershell skills and created this little powershell script which will add a text file next to the UPD with the username at the end of the filename.
Keep in mind, I’m not a devver, so I’m sure you can make this PowerShell script in a one or two liner but hey, it just works. 😉
My LAB UPD Store look like this at the moment:
After running the script it looks like this:
You can schedule this script to run every night. Or manually when needed.
<# Current Version 1.0 Creator: Jeroen Tielen - Tielen Consultancy - www.jeroentielen.nl History: Version 1.0 = Initial Script Description: This script will check the given UPD_Location for *.vhdx files and strip those file names to get the SID. Then it will query the active directory to get the username which belongs to this SID. It will then create a text file with the same name as the vhdx file and append the username at the end. If chosen to append the username at the end so the vhdx and txt file will be listed below each other (if sorted on file name). Change the script as you like. (for example make an array from $UPD_Location and tweak the foreach loop a little so you can add multiple UPD locations.) THE SCRIPT WILL NOT DELETE VHDX FILES BUT ONLY ADD A TXT FILE. Howto use: Change the two paramters at the top and run script with user wh has rights to write at the specified location. #> #-------------------------------- Change This -------------------------------- $UPD_Location = "\\FILESERVER.LAB.LOCAL\MS_UPD\WS2016" # The location where the Microsoft User Profile Disks are stored and where the txt files will be created. $DomainName = "LAB" # Pre-Windows2000 Domain name. This part will be stripped in the file name as is also contains a "backslash" #-------------------------------- Script -------------------------------- $Files = gci $UPD_Location -Name Foreach ($SID in $Files) { If ($SID -match ".vhdx") { $SID = $SID.Substring(5) -replace ".vhdx" If ($SID-match "template") { Write-Host "Template File" } Else { $objSID = New-Object System.Security.Principal.SecurityIdentifier ($SID) $objUser = $objSID.Translate( [System.Security.Principal.NTAccount]) $UserName = $objUSer.Value.trim("$DomainName\") $TextFile = $UPD_Location + "\UVHD-" + $SID + " " + $UserName + ".txt" New-Item $TextFile -ItemType file -Force } } }
Click to: Download
I found this script from https://learn.microsoft.com/en-us/answers/questions/1005700/show-usermame-linked-to-upd-drive
I would like to point out that your script doesn’t properly handle the situation where the user has been deleted. The script will apply the username from a previous file, because the variables are not initialized each time.
I am not a coder either, but I have updated the script to put “UNKNOWN” if the SID cannot be translated back to a username.
#——————————– Script ——————————–
$Files = gci $UPD_Location -Name
Foreach ($SID in $Files) {
If ($SID -match “.vhdx”) {
$SID = $SID.Substring(5) -replace “.vhdx”
If ($SID-match “template”) {
Write-Host “Template File”
} Else {
$objUser = “UNKNOWN”
$UserName = “UNKNOWN”
$objSID = New-Object System.Security.Principal.SecurityIdentifier ($SID)
$objUser = $objSID.Translate( [System.Security.Principal.NTAccount])
$UserName = $objUSer.Value.trim(“$DomainName\”)
$TextFile = $UPD_Location + “\UVHD-” + $SID + ” ” + $UserName + “.txt”
New-Item $TextFile -ItemType file -Force
}
}
}
Hi Kevin,
UPD should not be used anymore. You should switch to FSLogix 😉