WinProfileOps.psd1

#
# Module manifest for module 'WinProfileOps'
#
# Generated by: LarryWisherMan
#
# Generated on: 9/6/2024
#

@{

    # Script module or binary module file associated with this manifest.
    RootModule           = 'WinProfileOps.psm1'

    # Version number of this module.
    ModuleVersion        = '0.2.0'

    # Supported PSEditions
    # CompatiblePSEditions = @()

    # ID used to uniquely identify this module
    GUID                 = '1abff4b3-dadd-480c-a825-2671dfb7b3bd'

    # Author of this module
    Author               = 'LarryWisherMan'

    # Company or vendor of this module
    CompanyName          = 'LarryWisherMan'

    # Copyright statement for this module
    Copyright            = '(c) 2024 LarryWisherMan. All rights reserved.'

    # Description of the functionality provided by this module
    Description          = 'The WinProfileOps module provides a comprehensive toolkit for managing Windows user profiles across local and remote computers. This module automates profile management tasks such as detecting orphaned profiles, retrieving profile information, and auditing discrepancies between profile data in the file system and the registry. It handles both filesystem and registry operations, leveraging its dependency on WinRegOps for registry-related tasks.

WinProfileOps integrates seamlessly with WinRegOps to query, validate, and manage user profile-related data from the Windows registry. This module is ideal for system administrators seeking to streamline profile management, especially in environments with many users and computers.

Dependencies:
- WinRegOps: WinProfileOps depends on WinRegOps for registry operations, such as querying, opening, and modifying registry keys related to user profiles.

Key features:
- Retrieve user profile information from both the registry and file system (local and remote).
- Detect orphaned profiles (e.g., missing profile folders or registry entries).
- Filter and exclude special accounts like system or service accounts.
- Remote profile management support for retrieving profiles from different systems.
- Robust error handling for permission issues or unreachable systems.
- Class-based profile objects for easy integration with automation tasks or scripts.

Typical use cases include:
- Cleaning up orphaned profiles after system migrations or user deactivations.
- Automating stale profile detection on local and remote systems to maintain system performance.
- Managing user profiles in large-scale, multi-user environments such as terminal servers and Citrix.
- Excluding critical system accounts from profile management tasks, ensuring important profiles remain unaffected.
- Providing profile management as part of system maintenance routines to enhance system health.

Upcoming Features:
- The `Remove-UserProfile` function is coming soon, offering safe removal of user profiles from both the file system and registry, with strong safeguards like `ShouldProcess`, `-WhatIf`, and `-Confirm` to prevent accidental deletions.
'


    # Minimum version of the Windows PowerShell engine required by this module
    PowerShellVersion    = '5.1'

    # Name of the Windows PowerShell host required by this module
    # PowerShellHostName = ''

    # Minimum version of the Windows PowerShell host required by this module
    # PowerShellHostVersion = ''

    # Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
    # DotNetFrameworkVersion = ''

    # Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
    # CLRVersion = ''

    # Processor architecture (None, X86, Amd64) required by this module
    # ProcessorArchitecture = ''

    # Modules that must be imported into the global environment prior to importing this module
    RequiredModules      = @('WisherTools.Helpers')

    # Assemblies that must be loaded prior to importing this module
    # RequiredAssemblies = @()

    # Script files (.ps1) that are run in the caller's environment prior to importing this module.
    # ScriptsToProcess = @()

    # Type files (.ps1xml) to be loaded when importing this module
    # TypesToProcess = @()

    # Format files (.ps1xml) to be loaded when importing this module
    # FormatsToProcess = @()

    # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
    NestedModules        = @('.//Modules/WinRegOps/0.3.0/WinRegOps.psd1')

    # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
    FunctionsToExport    = @('Get-OrphanedProfiles','Get-UserProfilesFromFolders','Get-UserProfilesFromRegistry','Invoke-UserProfileAudit')

    # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
    CmdletsToExport      = @()

    # Variables to export from this module
    VariablesToExport    = @()

    # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
    AliasesToExport      = 'Get-AllUserProfiles'

    # DSC resources to export from this module
    DscResourcesToExport = @()

    # List of all modules packaged with this module
    # ModuleList = @()

    # List of all files packaged with this module
    # FileList = @()

    # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
    PrivateData          = @{

        PSData = @{

            Prerelease   = 'preview0003'
            # Tags applied to this module. These help with module discovery in online galleries.
            Tags         = @(
                'WindowsProfiles',
                'ProfileManagement',
                'OrphanedProfiles',
                'RegistryOperations',
                'FilesystemOperations',
                'RemoteManagement',
                'UserProfiles',
                'ProfileCleanup',
                'WindowsRegistry',
                'SystemAdministration',
                'Automation',
                'ProfileValidation',
                'WindowsManagement',
                'ITAdministration',
                'UserProfileTools'
            )

            # A URL to the license for this module.
            LicenseUri   = 'https://github.com/LarryWisherMan/WinProfileOps/blob/main/LICENSE'

            # A URL to the main website for this project.
            ProjectUri   = 'https://github.com/LarryWisherMan/WinProfileOps'

            # A URL to an icon representing this module.
            IconUri      = 'https://raw.githubusercontent.com/LarryWisherMan/ModuleIcons/main/WinProfileOps.png'

            # ReleaseNotes of this module
            ReleaseNotes = '## [0.2.0-preview0003] - 2024-09-12

### Added

- Added core functions
- configured `WinRegOps` as a dependant module
- Updated build file for release

- Comment-based help documentation added for the following public functions:
  - `Get-AllUserProfiles`
  - `Get-OrphanedProfiles`
  - `Remove-OrphanedProfiles`
  - `Remove-SIDProfile`
  - `Get-UserProfileFolders`
  - `Get-RegistryUserProfiles`
  - `Get-UserFolders`

- Comment-based help documentation added for the following public functions:
  - `New-UserProfileObject`
  - `Remove-RegistryKeyForSID`
  - `Remove-ProfilesForSIDs`
  - `Get-RegistryKeyForSID`
  - `Get-SIDProfileInfo`
  - `Get-ProfilePathFromSID`
  - `Test-FolderExists`
  - `Test-OrphanedProfile`
  - `Test-SpecialAccount`

- Implemented and completed Unit Tests for private functions

- **`Get-UserFolders`**
  - Added error handling using a `try`/`catch` block to ensure that if `Get-ChildItem`
   fails (e.g., due to permission issues), the function logs an error message and
   returns an empty array instead of throwing an unhandled exception.

  - Implemented an `OutputType` attribute for better PowerShell function introspection
   and to clearly indicate that the function returns an array of `[PSCustomObject]`.

- **`Invoke-UserProfileAudit` Supporting Functions:**

  - These supporting functions are now utilized within `Invoke-UserProfileAudit`
   to audit user profiles from both the file system and registry sources.

    - **`Process-RegistryProfiles`**:
      - Processes profiles retrieved from the registry,
    compares them with folder profiles, and identifies orphaned profiles.

    - **`Process-FolderProfiles`**:
      - Processes user profiles from the folder system,
     identifies those without corresponding registry entries, and marks them as orphaned.

    - **`Test-ComputerReachability`**:
      - Encapsulates the common behavior of `Test-ComputerPing` to check if a computer
      is reachable before proceeding with operations like profile audits. This ensures
       consistent handling of unreachable computers across different functions.
  
### Changed

- Moved `Get-SIDProfileInfo` to the private functions folder. It will serve as
an internal function for `Get-RegistryUserProfiles`

- **`Get-SIDProfileInfo`**
  - Returns an empty array `@()` when no registry
  key or SIDs are found, improving handling for cases where there are no profiles.

  - Improved error handling to ensure proper error messages when the registry key
  or subkeys cannot be opened.

  - Enhanced handling of SIDs that are invalid or missing a `ProfileImagePath`,
  logging appropriate warnings or verbose messages.

  - Optimized function behavior to handle scenarios with no SIDs, invalid SID formats,
  and missing `ProfileImagePath` values gracefully.


- **`Get-UserFolders`**
  - The function now logs errors when folder retrieval fails, improving diagnostic
   feedback.

  - The default value for the `ComputerName` parameter is set to `$env:COMPUTERNAME`,
   ensuring local computer behavior by default without requiring the user to
   specify it manually.
  
  - Refined the `Get-DirectoryPath` call to ensure path conversion consistency
   across local and remote environments.

  - General code clean-up and improved resilience, returning an empty array when
   no folders are found or in case of failure, rather than proceeding
   without valid data.

- **`Get-UserProfilesFromRegistry`**
  - Added error handling using a `try-catch` block to capture and log errors
   during the retrieval of registry profiles.

  - Implemented a check using `Test-ComputerPing` to verify if the target computer
   is online or reachable before attempting to retrieve registry profiles.

  - Returns an empty array `@()` when the target computer is offline or unreachable,
   logging a warning in such cases.

  - Returns an empty array `@()` when an error occurs while accessing the registry
   profiles, logging an error message.

  - Integrated with the `-ErrorAction Stop` parameter when calling `Get-SIDProfileInfo`,
   ensuring that errors are caught and handled appropriately in the calling function.

- **`Get-UserProfilesFromFolders`**
  - Added error handling using a `try-catch` block to capture and log errors
   during the retrieval of user profile folders.

  - Implemented a check using `Test-ComputerPing` to verify if the target
   computer is online or reachable before attempting to retrieve user folders.

  - Returns an empty array `@()` when the target computer is offline or
   unreachable, logging a warning in such cases.

  - Returns an empty array `@()` when an error occurs while accessing the user
   folders, logging an error message.


- **`Invoke-UserProfileAudit`**
  - Renamed the previous `Get-AllUserProfiles` function to `Invoke-UserProfileAudit`.
  - Added `Get-AllUserProfiles` as an alias for `Invoke-UserProfileAudit`
  to maintain backward compatibility.

### Removed

- Removed the old `Get-AllUserProfiles` function and replaced it with the new
`Invoke-UserProfileAudit` function.

- Temporarily Removed functions (`Remove-OrphanedProfiles` and
 `Remove-ProfilesForSIDs`) related to Removing Users Folders and registry
keys for further testing before implementing
'


        } # End of PSData hashtable

    } # End of PrivateData hashtable

    # HelpInfo URI of this module
    # HelpInfoURI = ''

    # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
    # DefaultCommandPrefix = ''

}