Skip to content

Commit

Permalink
Merge pull request #1 from LarryWisherMan/feature/FunctionSetup
Browse files Browse the repository at this point in the history
Feature/function setup
  • Loading branch information
LarryWisherMan authored Sep 9, 2024
2 parents 478f633 + 633f665 commit 6690141
Show file tree
Hide file tree
Showing 36 changed files with 608 additions and 575 deletions.
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"files.trimTrailingWhitespace": true,
"files.trimFinalNewlines": true,
"files.insertFinalNewline": true,
"files.autoSave": "afterDelay", // Enables autosave after a delay
"files.autoSaveDelay": 1000, // Autosave after 1 second of inactivity (1000ms)
"editor.formatOnSave": true, // Enables format on save
"files.associations": {
"*.ps1xml": "xml"
},
Expand All @@ -37,5 +40,8 @@
"[markdown]": {
"files.trimTrailingWhitespace": false,
"files.encoding": "utf8"
}
},
"conventionalCommits.scopes": [
"WinProfileOps"
]
}
25 changes: 3 additions & 22 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- For new features.

### Changed

- For changes in existing functionality.

### Deprecated

- For soon-to-be removed features.

### Removed

- For now removed features.

### Fixed

- For any bug fix.

### Security

- In case of vulnerabilities.

- Added core functions
- configured `WinRegOps` as a dependant module
- Updated build file for release
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,3 @@ Typical use cases include:
- Managing user profiles in large-scale, multi-user environments (e.g., terminal servers, Citrix environments).
- Excluding system accounts from profile cleanup operations, ensuring important profiles remain intact.
- Providing profile management capabilities as part of system maintenance routines.

## Make it yours

---
Generated with Plaster and the SampleModule template


This is a sample Readme

## Make it yours
23 changes: 15 additions & 8 deletions RequiredModules.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@
# }
#}

InvokeBuild = 'latest'
PSScriptAnalyzer = 'latest'
Pester = 'latest'
ModuleBuilder = 'latest'
ChangelogManagement = 'latest'
Sampler = 'latest'
'Sampler.GitHubTasks' = 'latest'
'WisherTools.Helpers' = 'latest'
InvokeBuild = 'latest'
PSScriptAnalyzer = 'latest'
Pester = 'latest'
ModuleBuilder = 'latest'
ChangelogManagement = 'latest'
Sampler = 'latest'
'Sampler.GitHubTasks' = 'latest'
#'WisherTools.Helpers' = 'latest'
'WinRegOps' = @{
Version = '0.3.0-preview0003'
Parameters = @{
AllowPrerelease = $true
Repository = "PSGallery"
}
}


}
37 changes: 23 additions & 14 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
# Path to the Module Manifest to build (where path will be resolved from)
# SourcePath: ./Sampler/Sampler.psd1
# Output Directory where ModuleBuilder will build the Module, relative to module manifest
# OutputDirectory: ../output/Sampler
OutputDirectory: ../output/module
BuiltModuleSubdirectory: module
CopyPaths:
- en-US
# - DSCResources
# - Modules
# - Modules
Encoding: UTF8
# Can be used to manually specify module's semantic version if the preferred method of
# using GitVersion is not available, and it is not possible to set the session environment
Expand All @@ -28,6 +28,13 @@ VersionedOutputDirectory: true
####################################################

NestedModule:
WinRegOps: # This is the first submodule to build into the output
CopyOnly: true
Path: ./output/RequiredModules/WinRegOps
AddToManifest: True

# # is trimmed (remove metadata & Prerelease tag) and OutputDirectory expanded (the only one)
# VersionedOutputDirectory: false
# HelperSubmodule: # This is the first submodule to build into the output
# Path: ./*/Modules/HelperSubmodule/HelperSubmodule.psd1
# # is trimmed (remove metadata & Prerelease tag) and OutputDirectory expanded (the only one)
Expand All @@ -43,7 +50,7 @@ NestedModule:
####################################################
# Defining 'Workflows' (suite of InvokeBuild tasks) to be run using their alias
BuildWorkflow:
'.': # "." is the default Invoke-Build workflow. It is called when no -Tasks is specified to the build.ps1
".": # "." is the default Invoke-Build workflow. It is called when no -Tasks is specified to the build.ps1
- build
- test

Expand All @@ -53,13 +60,10 @@ BuildWorkflow:
- Build_NestedModules_ModuleBuilder
- Create_changelog_release_output


pack:
- build
- package_module_nupkg



# Defining test task to be run when invoking `./build.ps1 -Tasks test`
test:
# Uncomment to modify the PSModulePath in the test pipeline (also requires the build configuration section SetPSModulePath).
Expand All @@ -73,10 +77,9 @@ BuildWorkflow:
# Use this task when you have multiple parallel tests, which produce multiple
# code coverage files and needs to get merged into one file.
#merge:
#- Merge_CodeCoverage_Files
#- Merge_CodeCoverage_Files

publish:

- Publish_Release_To_GitHub # Runs first, if token is expired it will fail early
- publish_module_to_gallery

Expand All @@ -88,6 +91,7 @@ Pester:
OutputFormat: NUnitXML
# Excludes one or more paths from being used to calculate code coverage.
ExcludeFromCodeCoverage:
- Modules/WinRegOps

# If no scripts are defined the default is to use all the tests under the project's
# tests folder or source folder (if present). Test script paths can be defined to
Expand Down Expand Up @@ -117,20 +121,18 @@ Pester:
# CodeCoverageMergedOutputFile - the file that is created by the merge build task and
# is the file that should be uploaded to code coverage services.
#CodeCoverage:
#CodeCoverageFilePattern: JaCoCo_Merge.xml # the pattern used to search all pipeline test job artifacts
#CodeCoverageMergedOutputFile: JaCoCo_coverage.xml # the file that is created for the merged code coverage

#CodeCoverageFilePattern: JaCoCo_Merge.xml # the pattern used to search all pipeline test job artifacts
#CodeCoverageMergedOutputFile: JaCoCo_coverage.xml # the file that is created for the merged code coverage

# Import ModuleBuilder tasks from a specific PowerShell module using the build
# task's alias. Wildcard * can be used to specify all tasks that has a similar
# prefix and or suffix. The module contain the task must be added as a required
# module in the file RequiredModules.psd1.
ModuleBuildTasks:
Sampler:
- '*.build.Sampler.ib.tasks'
- "*.build.Sampler.ib.tasks"
Sampler.GitHubTasks:
- '*.ib.tasks'

- "*.ib.tasks"

# Invoke-Build Header to be used to 'decorate' the terminal output of the tasks.
TaskHeader: |
Expand All @@ -143,3 +145,10 @@ TaskHeader: |
Write-Build DarkGray " $Path"
Write-Build DarkGray " $($Task.InvocationInfo.ScriptName):$($Task.InvocationInfo.ScriptLineNumber)"
""
GitHubConfig:
GitHubFilesToAdd:
- "CHANGELOG.md"
GitHubConfigUserName: LarryWisherMan
GitHubConfigUserEmail: MikeRow@upkep.net
UpdateChangelogOnPrerelease: false
15 changes: 0 additions & 15 deletions source/Classes/1.class1.ps1

This file was deleted.

14 changes: 0 additions & 14 deletions source/Classes/2.class2.ps1

This file was deleted.

13 changes: 0 additions & 13 deletions source/Classes/3.class11.ps1

This file was deleted.

13 changes: 0 additions & 13 deletions source/Classes/4.class12.ps1

This file was deleted.

16 changes: 16 additions & 0 deletions source/Classes/ProfileDeletionResult.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class ProfileDeletionResult {
[string]$SID
[string]$ProfilePath
[bool]$DeletionSuccess
[string]$DeletionMessage
[string]$ComputerName

# Constructor to initialize the properties
ProfileDeletionResult([string]$sid, [string]$profilePath, [bool]$deletionSuccess, [string]$deletionMessage, [string]$computerName) {
$this.SID = $sid
$this.ProfilePath = $profilePath
$this.DeletionSuccess = $deletionSuccess
$this.DeletionMessage = $deletionMessage
$this.ComputerName = $computerName
}
}
18 changes: 18 additions & 0 deletions source/Classes/UserProfile.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class UserProfile {
[string]$SID
[string]$ProfilePath
[bool]$IsOrphaned
[string]$OrphanReason
[string]$ComputerName
[bool]$IsSpecial

# Constructor to initialize the properties
UserProfile([string]$sid, [string]$profilePath, [bool]$isOrphaned, [string]$orphanReason, [string]$computerName, [bool]$isSpecial) {
$this.SID = $sid
$this.ProfilePath = $profilePath
$this.IsOrphaned = $isOrphaned
$this.OrphanReason = $orphanReason
$this.ComputerName = $computerName
$this.IsSpecial = $isSpecial
}
}
31 changes: 0 additions & 31 deletions source/Private/Get-PrivateFunction.ps1

This file was deleted.

70 changes: 70 additions & 0 deletions source/Public/Get-AllUserProfiles.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
function Get-AllUserProfiles {
[CmdletBinding()]
param (
[Parameter(Mandatory = $false, ValueFromPipeline = $true)]
[string]$ComputerName = $env:COMPUTERNAME,

[string]$ProfileFolderPath = "C:\Users",
[switch]$IgnoreSpecial
)

# Begin block runs once before processing pipeline input
begin {
# Initialize an array to hold all UserProfile objects across multiple pipeline inputs
$AllProfiles = @()
}

# Process block runs once for each input object (in case of pipeline)
process {
# Test if the computer is online before proceeding
if (-not (Test-ComputerPing -ComputerName $ComputerName)) {
Write-Warning "Computer '$ComputerName' is offline or unreachable."
return # Skip to the next input in the pipeline
}

# Get profiles from folders and registry
$UserFolders = Get-UserProfilesFromFolders -ComputerName $ComputerName -ProfileFolderPath $ProfileFolderPath
$RegistryProfiles = Get-UserProfilesFromRegistry -ComputerName $ComputerName

# Loop through registry profiles and check for folder existence and ProfileImagePath
foreach ($regProfile in $RegistryProfiles) {
$profilePath = $regProfile.ProfilePath
$folderExists = Test-FolderExists -ProfilePath $profilePath -ComputerName $regProfile.ComputerName
$folderName = Split-Path -Path $profilePath -Leaf
$isSpecial = Test-SpecialAccount -FolderName $folderName -SID $regProfile.SID -ProfilePath $profilePath

# Skip special profiles if IgnoreSpecial is set
if ($IgnoreSpecial -and $isSpecial) {
continue
}

# Detect if the profile is orphaned and create the user profile object
$userProfile = Test-OrphanedProfile -SID $regProfile.SID -ProfilePath $profilePath `
-FolderExists $folderExists -IgnoreSpecial $IgnoreSpecial `
-IsSpecial $isSpecial -ComputerName $ComputerName
$AllProfiles += $userProfile
}

# Loop through user folders and check if they exist in the registry
foreach ($folder in $UserFolders) {
$registryProfile = $RegistryProfiles | Where-Object { $_.ProfilePath -eq $folder.ProfilePath }
$isSpecial = Test-SpecialAccount -FolderName $folder.FolderName -SID $null -ProfilePath $folder.ProfilePath

# Skip special profiles if IgnoreSpecial is set
if ($IgnoreSpecial -and $isSpecial) {
continue
}

# Case 4: Folder exists in C:\Users but not in the registry
if (-not $registryProfile) {
$AllProfiles += New-UserProfileObject $null $folder.ProfilePath $true "MissingRegistryEntry" $ComputerName $isSpecial
}
}
}

# End block runs once after all processing is complete
end {
# Output all collected profiles
$AllProfiles
}
}
Loading

0 comments on commit 6690141

Please sign in to comment.