# Script must be run in a network allowed to access the AZstorage # check modules $module = Get-InstalledModule -Name "Az" $return = $module.Name | Select-String "Az" if ($null -eq $return) { Write-Host "Please install the Az Module" break } Import-Module Az.Accounts Import-Module Az.Storage # Prompt to start session Write-Host "Prompting for Azure Account" -ForegroundColor Green $null = Connect-AzAccount # Prompt for variables $subId = Read-Host -Prompt "SubscriptionID: " $rg = Read-Host -Prompt "Azure SA Resource Group: " $StorageName = Read-Host -Prompt "Storage Account Name: " $ShareName = Read-Host -Prompt "Azure Files Share Name: " $user = Read-Host -Prompt "Username with Locked Profile: " # Set context to ensure correct subscription is used Write-Host "setting subcription to: $subid " -ForegroundColor Green $null = Set-AzContext -SubscriptionId $subId # Set storage keys and create context, retrieve handles Write-Host "Searching for Handles matching $user :" -ForegroundColor Green Write-Host "================================= " -ForegroundColor Green $key = Get-AzStorageAccountkey -ResourceGroupName $rg -Name $StorageName $ctx = New-AzStorageContext -StorageAccountName $StorageName -StorageAccountKey $key.value[0] $getAzSFH = Get-AzStorageFileHandle -ShareName $ShareName -Recursive -context $ctx | Sort-Object ClientIP,OpenTime,Path # Iterate through handles, find ones that match username provided foreach ($vmIP in $getAzSFH){ if ($vmIP.path -match $user){ Write-Host -NoNewline "Handle found: " -ForegroundColor Gray Write-Host -NoNewline "IP: $($vmIp.ClientIP), " -ForegroundColor Cyan write-host "Path: $($vmIP.path) " -ForegroundColor Magenta } } Disconnect-AzAccount