better profile path selection
This commit is contained in:
@@ -8,21 +8,23 @@ Function Update-ListOfPaths {
|
||||
Function Add-UserProfilePaths {
|
||||
param([System.Collections.ArrayList]$List,[string]$Path)
|
||||
|
||||
# Get a list of all user profile directories
|
||||
$ProfilePath = (Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList' -Name ProfilesDirectory)
|
||||
$UserProfilePaths = @()
|
||||
ForEach ( $userProfile in (Get-ChildItem -Path $ProfilePath | Where-Object { $_.PSIsContainer }) ) {
|
||||
$UserProfilePaths += ,@($userProfile.FullName)
|
||||
}
|
||||
$ChildPath = ($Path -split '%')[2]
|
||||
|
||||
# Iterate over each $profilePath and join it with the supplied $Path
|
||||
ForEach ( $profilePath in $UserProfilePaths ) {
|
||||
# Get a list of all user profile directories
|
||||
ForEach ( $profile in (Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList') ) {
|
||||
$profileImagePath = Get-ItemPropertyValue -Path $([System.Environment]::ExpandEnvironmentVariables($profile.PSPath)) -Name ProfileImagePath
|
||||
|
||||
# Skip profiles located in C:\Windows as MSP360 doesn't currently include these when using the %UserProfile% variable
|
||||
If ( $profileImagePath -ilike "*${Env:WinDir}*" ) { Continue }
|
||||
|
||||
# Build the path we're trying to add
|
||||
$path = $(Join-Path -Path $profilePath -ChildPath $($Path -split '%')[2])
|
||||
$path = Join-Path -Path $profileImagePath -ChildPath $ChildPath
|
||||
|
||||
# Skip adding the path if it doesn't exist
|
||||
If ( !(Test-Path $path) ) { Continue }
|
||||
|
||||
# Only add the path if it exists (domain computers may have many invalid/old user accounts with nonexistant paths)
|
||||
If ( Test-Path $path ) { Update-ListOfPaths -List $List -Path $path }
|
||||
# Add the path
|
||||
Update-ListOfPaths -List $List -Path $path
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user