Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request
Pull Request (PR) description
Adds admin detection and fallback for non-admin profile retrieval in
Get-UserProfilesFromRegistry
, withGet-SIDProfileInfoFallback
for non-admin users.Added
New helper function
Validate-SIDFormat
to verify SID value upon retrievalin
Get-ProfilePathFromSID
Admin Detection and Environment Variable: Added logic to detect whether the
current user is an administrator and set an environment variable
WinProfileOps_IsAdmin
accordingly.If the user is an administrator,
$ENV:WinProfileOps_IsAdmin
is set to$true
. If not, it's set to$false
.The environment variable is automatically removed when the module is
unloaded or when PowerShell exits.
Registered an
OnRemove
script block and aPowerShell.Exiting
event toensure cleanup of the environment variable on module removal or session exit.
Get-SIDProfileInfoFallback: Introduced a new fallback function
Get-SIDProfileInfoFallback
that retrieves non-special user profileinformation using the CIM/WMI method.
Changed
Get-UserProfilesFromRegistry: Updated the function to handle scenarios
where the current user does not have administrative privileges.
The function now checks if the user is an administrator by evaluating the
WinProfileOps_IsAdmin
environment variable.If the user has administrator privileges, the function retrieves user
profiles from the registry using
Get-SIDProfileInfo
.If the user lacks administrative privileges, the function falls back to the
Get-SIDProfileInfoFallback
method, which retrieves user profiles usingCIM/WMI without requiring registry access.
A warning is logged when the fallback method is used, indicating that
special system accounts are excluded.