Hello, @Swaroop Gowda D !
I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer.
Issue:
I would like to access the details of inactive users who have not logged into Azure Virtual Desktop for 90 days. Specifically, I would like to know their usage in the file share as well as their last logon details.
Solution (provided by Swaroop Gowda D):
My objective was to identify users who haven't logged into AVD for the past 60 days and remove their profile details from the Azure file share, without affecting their user accounts. Due to insufficient information from the Microsoft Q&A platform and the inability to gather the necessary details, I developed a PowerShell script. This script captures details such as directory name, file name/profile name, profile size, and last modified date. Using these last modified details, I can proceeded to delete the user profiles from the Azure file share where all user profiles are stored. Below is the PowerShell script:
# Install the Export-Excel module if not already installed
Install-Module -Name ImportExcel -Force -AllowClobber
# Input Parameters
$resourceGroupName = "resourceGroupName"
$storageAccName = "storageAccName"
$fileShareName = "fileShareName"
$directoryPath = "Presentation"
# Specify the customer's tenant ID
$customerTenantId = "customerTenantId"
# Azure login to the customer's tenant
Connect-AzAccount -Tenant $customerTenantId
# Set the default subscription
Set-AzContext -SubscriptionId "SubscriptionId"
# Import the Export-Excel module
Import-Module ImportExcel
# Function to Lists directories and files along with their sizes in MB and exports to Excel
Function GetFiles {
Write-Host -ForegroundColor Green "Listing directories and files with sizes, creation date, and last modified date in MB.."
# Get the storage account context
$ctx = (Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName).Context
# Create an array to store file details
$fileDetails = @()
# List directories
$directories = Get-AZStorageFile -Context $ctx -ShareName $fileShareName
# Loop through directories
foreach ($directory in $directories) {
Write-Host -ForegroundColor Magenta "Directory Name: $($directory.Name)"
# List files in the current directory
$files = Get-AZStorageFile -Context $ctx -ShareName $fileShareName -Path $directory.Name | Get-AzStorageFile
# Loop through files
foreach ($file in $files) {
# Convert size to MB
$sizeInMB = [math]::Round($file.Length / 1MB, 2)
# Add file details to the array with size, last modified date
$fileDetails += [PSCustomObject]@{
DirectoryName = $directory.Name
FileName = $file.Name
Size_MB = $sizeInMB
LastModified = $file.LastModified.LocalDateTime # Retrieve LastModified directly
}
}
}
# Specify the new export path
$exportPath = "add your file path to downloas in xls file"
# Export to Excel with additional LastModified property with custom date format (yyyy-MM-dd HH:mm)
$fileDetails | Export-Excel -Path $exportPath -AutoSize -Show
}
# Call the function
GetFiles