2 thoughts on “Add username textfile to Microsoft User Profile Disks fileshare

  1. 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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top