-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from LarryWisherMan/feature-PublicTests
Refactor Profile Management Functions and Introduce Enhanced Error Handling*
- Loading branch information
Showing
31 changed files
with
2,595 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,3 +57,6 @@ function Remove-OrphanedProfiles | |
# Step 4: Return the results of the removal process | ||
return $removalResults | ||
} | ||
|
||
|
||
|
File renamed without changes.
10 changes: 10 additions & 0 deletions
10
source/NotImplemented/RemoveUserProfile/Private/Is-SpecialProfile.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function Is-SpecialProfile | ||
{ | ||
param ( | ||
[string]$FolderName, | ||
[string]$SID, | ||
[string]$ProfilePath | ||
) | ||
|
||
return Test-SpecialAccount -FolderName $FolderName -SID $SID -ProfilePath $ProfilePath | ||
} |
29 changes: 29 additions & 0 deletions
29
source/NotImplemented/RemoveUserProfile/Private/Remove-UserFolder.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
function Remove-UserFolder | ||
{ | ||
param ( | ||
[PSCustomObject]$ProfileDetails, | ||
[switch]$Force | ||
) | ||
|
||
if ($PSCmdlet.ShouldProcess($ProfileDetails.ProfilePath, "Remove user profile folder")) | ||
{ | ||
try | ||
{ | ||
if (Test-Path -Path $ProfileDetails.ProfilePath) | ||
{ | ||
Remove-Item -Path $ProfileDetails.ProfilePath -Recurse -Force -Confirm:$Force | ||
return [ProfileDeletionResult]::new($ProfileDetails.SID, $ProfileDetails.ProfilePath, $true, "Profile folder removed successfully.", $env:COMPUTERNAME) | ||
} | ||
else | ||
{ | ||
Write-Warning "Profile folder not found: $($ProfileDetails.ProfilePath)" | ||
return [ProfileDeletionResult]::new($ProfileDetails.SID, $ProfileDetails.ProfilePath, $false, "Profile folder not found.", $env:COMPUTERNAME) | ||
} | ||
} | ||
catch | ||
{ | ||
Write-Error "Error removing profile folder: $_" | ||
return [ProfileDeletionResult]::new($ProfileDetails.SID, $ProfileDetails.ProfilePath, $false, "Error removing profile folder: $_", $env:COMPUTERNAME) | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
source/NotImplemented/RemoveUserProfile/Private/Resolve-ProfileDetails.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
function Resolve-ProfileDetails | ||
{ | ||
param ( | ||
[PSCustomObject]$UserProfile, | ||
[string]$UserName, | ||
[string]$SID | ||
) | ||
|
||
if ($UserProfile) | ||
{ | ||
return [PSCustomObject]@{ | ||
SID = $UserProfile.SID | ||
ProfilePath = $UserProfile.ProfilePath | ||
FolderName = Split-Path -Path $UserProfile.ProfilePath -Leaf | ||
} | ||
} | ||
elseif ($UserName) | ||
{ | ||
$sid = (Get-WmiObject -Class Win32_UserAccount -Filter "Name='$UserName'" | Select-Object -ExpandProperty SID) | ||
$profilePath = [System.IO.Path]::Combine("$env:SystemDrive\Users", $UserName) | ||
return [PSCustomObject]@{ | ||
SID = $sid | ||
ProfilePath = $profilePath | ||
FolderName = $UserName | ||
} | ||
} | ||
elseif ($SID) | ||
{ | ||
$profilePath = (Get-WmiObject -Class Win32_UserProfile -Filter "SID='$SID'" | Select-Object -ExpandProperty LocalPath) | ||
return [PSCustomObject]@{ | ||
SID = $SID | ||
ProfilePath = $profilePath | ||
FolderName = Split-Path -Path $profilePath -Leaf | ||
} | ||
} | ||
return $null | ||
} |
Oops, something went wrong.