Forum Discussion
How to fetch username or userEmail from userprofile details of FSLogix
Try this, please make sure you are fully understand the script before applying:
$Profiles = Get-ChildItem -Recurse -Path $FileSharePath -Filter "*.VHDX" -ErrorAction Stop |
ForEach-Object {
$userGPN = ($_.Name -split '_')[1].Split('.')[0]
$userEmail = Get-ADUser -Filter {SamAccountName -eq $userGPN} | Select-Object -ExpandProperty UserPrincipalName
[PSCustomObject]@{
UserGPN = $userGPN
UserEmail = $userEmail
FileShareName = ($_.FullName -split '\\')[3]
FileName = $_.Name
TotalSizeInGB = $DriveSizeGB
ConsumedSizeInGB = [math]::Round($_.Length / 1GB, 2)
FilePath = $_.FullName
CreationTimeUtc = $_.CreationTimeUtc.ToString()
LastAccessTimeUtc = $_.LastAccessTimeUtc.ToString()
LastWriteTimeUtc = $_.LastWriteTimeUtc.ToString()
}
}
Hi Kidd_Ip
Thanks for your reply.
I understand that for getting user email you are passing user GPN to Get-ADUser command to find user in AD, but what if we have 2 or more user with same Display name but with different UPN or Email ID in AD. What we can do in that case?
Kindly help