Forum Discussion
How to fetch username or userEmail from userprofile details of FSLogix
Hi
I am trying to fetch several details from FSLogix userprofile like disk size usage , last accessed date. I need to get user details as well like Username or UserEmail.
Below is the PS Snippet that I am using.
$Profiles = Get-ChildItem -Recurse -Path $FileSharePath -Filter "*.VHDX" -ErrorAction Stop |
ForEach-Object {
[PSCustomObject]@{
UserGPN = ($_.Name -split '_')[1].Split('.')[0]
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()
}
}
How can I get that ? Kindly help!
Thanks
Hirdesh
3 Replies
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()
}
}- Lancelotbaghel30Copper Contributor
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
- Erick_DanielMCopper Contributor
Try with this, i'm using this PS, first mount the StorageAccount path in PC, modify the path and name where tho doc 'ill be located and then run the PS
Get-ChildItem -Path Y:\ -Filter *.VHDX -Recurse |`
foreach{
$Item = $_
$Type = $_.Extension
$Path = $_.FullName
$Folder = $_.PSIsContainer
$Age = $_.LastWriteTime
$Size = $_.Length
$Age2 = $_.CreationTime$Path | Select-Object `
@{n="Name";e={$Item}},`
@{n="Last_Write";e={$Age}},`
@{n="filePath";e={$Path}},`
@{n="Lenght";e={$Size}},`
@{n="CreationTime";e={$Age2}},`
@{n="Extension";e={if($Folder){"Folder"}else{$Type}}}`
}| Export-Csv C:\Path\DocName.csv -NoTypeInformation