-
Notifications
You must be signed in to change notification settings - Fork 8
Cut 4862 status reporting v2 #235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
79bb3c6
78920e0
61d943b
c82c0a3
f2393a7
b6c271e
b8ce776
a49569d
72c9d93
d4c3fd1
edfd3d0
771b444
0c62816
9a87ce6
25d6462
8d48a84
51b3341
a572e68
177510e
9e9f5cc
dcd45ab
e153a9e
f06448c
4af0caf
fde027a
aa12292
287664b
c06da67
196bf66
050e157
4f12f26
2002c7c
a8ffe74
26b6af8
ec892d1
6cf176b
4658acf
2d0df2d
e857253
527634d
ed7149d
55c94b3
dcd531b
53eaa99
fd2c030
72bb317
d8dc145
311600e
b87d6e2
c948af6
5fd03bf
38e797d
0554a9b
fb3a635
943a273
622c474
3b64513
3fd6f4c
ed3f610
1c90e08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,201 @@ | ||
| --- | ||
| external help file: JumpCloud.ADMU-help.xml | ||
| Module Name: JumpCloud.ADMU | ||
| online version: https://github.com/TheJumpCloud/jumpcloud-ADMU/wiki/Start-Reversion | ||
| schema: 2.0.0 | ||
| --- | ||
|
|
||
| # Start-Reversion | ||
|
|
||
| ## SYNOPSIS | ||
| Reverts a user migration by restoring original registry files for a specified Windows SID. | ||
|
|
||
| ## SYNTAX | ||
|
|
||
| ``` | ||
| Start-Reversion [-UserSID] <String> [[-TargetProfileImagePath] <String>] [-form <Boolean>] [-UserName <String>] | ||
| [-ProfileSize <String>] [-DryRun] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>] | ||
| ``` | ||
|
|
||
| ## DESCRIPTION | ||
| This function reverts a user migration by: | ||
| 1. | ||
| Looking up the account SID in the Windows registry ProfileList | ||
| 2. | ||
| Identifying the .ADMU profile path | ||
| 3. | ||
| Restoring original NTUSER.DAT and UsrClass.dat files from backups | ||
| 4. | ||
| Preserving migrated files with _migrated suffix for rollback purposes | ||
|
|
||
| ## EXAMPLES | ||
|
|
||
| ### EXAMPLE 1 | ||
| ``` | ||
| Start-Reversion -UserSID "S-1-5-21-123456789-1234567890-123456789-1001" | ||
| Reverts the migration for the specified user SID using the registry profile path. | ||
| ``` | ||
|
|
||
| ### EXAMPLE 2 | ||
| ``` | ||
| Start-Reversion -UserSID "S-1-5-21-123456789-1234567890-123456789-1001" -TargetProfileImagePath "C:\Users\john.doe" | ||
| Reverts the migration using a specific target profile path instead of the registry value. | ||
| ``` | ||
|
|
||
| ### EXAMPLE 3 | ||
| ``` | ||
| Start-Reversion -UserSID "S-1-5-21-123456789-1234567890-123456789-1001" -DryRun | ||
| Shows what would be reverted without making actual changes. | ||
| ``` | ||
|
|
||
| ## PARAMETERS | ||
|
|
||
| ### -UserSID | ||
| The Windows Security Identifier (SID) of the user account to revert. | ||
|
|
||
| ```yaml | ||
| Type: System.String | ||
| Parameter Sets: (All) | ||
| Aliases: | ||
|
|
||
| Required: True | ||
| Position: 1 | ||
| Default value: None | ||
| Accept pipeline input: False | ||
| Accept wildcard characters: False | ||
| ``` | ||
|
|
||
| ### -TargetProfileImagePath | ||
| The actual profile path to revert. | ||
| If not specified, will use the path from the registry. | ||
| This path will be validated to ensure it exists and is associated with the UserSID. | ||
|
|
||
| ```yaml | ||
| Type: System.String | ||
| Parameter Sets: (All) | ||
| Aliases: | ||
|
|
||
| Required: False | ||
| Position: 2 | ||
| Default value: None | ||
| Accept pipeline input: False | ||
| Accept wildcard characters: False | ||
| ``` | ||
|
|
||
| ### -form | ||
| {{ Fill form Description }} | ||
|
|
||
| ```yaml | ||
| Type: System.Boolean | ||
| Parameter Sets: (All) | ||
| Aliases: | ||
|
|
||
| Required: False | ||
| Position: Named | ||
| Default value: False | ||
| Accept pipeline input: False | ||
| Accept wildcard characters: False | ||
| ``` | ||
|
|
||
| ### -UserName | ||
| {{ Fill UserName Description }} | ||
|
||
|
|
||
| ```yaml | ||
| Type: System.String | ||
| Parameter Sets: (All) | ||
| Aliases: | ||
|
|
||
| Required: False | ||
| Position: Named | ||
| Default value: None | ||
| Accept pipeline input: False | ||
| Accept wildcard characters: False | ||
| ``` | ||
|
|
||
| ### -ProfileSize | ||
| {{ Fill ProfileSize Description }} | ||
|
||
|
|
||
| ```yaml | ||
| Type: System.String | ||
| Parameter Sets: (All) | ||
| Aliases: | ||
|
|
||
| Required: False | ||
| Position: Named | ||
| Default value: None | ||
| Accept pipeline input: False | ||
| Accept wildcard characters: False | ||
| ``` | ||
|
|
||
| ### -DryRun | ||
| Shows what actions would be performed without actually executing them. | ||
|
|
||
| ```yaml | ||
| Type: System.Management.Automation.SwitchParameter | ||
| Parameter Sets: (All) | ||
| Aliases: | ||
|
|
||
| Required: False | ||
| Position: Named | ||
| Default value: False | ||
| Accept pipeline input: False | ||
| Accept wildcard characters: False | ||
| ``` | ||
|
|
||
| ### -Force | ||
| Bypasses confirmation prompts and forces the revert operation. | ||
|
|
||
| ```yaml | ||
| Type: System.Management.Automation.SwitchParameter | ||
| Parameter Sets: (All) | ||
| Aliases: | ||
|
|
||
| Required: False | ||
| Position: Named | ||
| Default value: False | ||
| Accept pipeline input: False | ||
| Accept wildcard characters: False | ||
| ``` | ||
|
|
||
| ### -WhatIf | ||
| Shows what would happen if the cmdlet runs. | ||
| The cmdlet is not run. | ||
|
|
||
| ```yaml | ||
| Type: System.Management.Automation.SwitchParameter | ||
| Parameter Sets: (All) | ||
| Aliases: wi | ||
|
|
||
| Required: False | ||
| Position: Named | ||
| Default value: None | ||
| Accept pipeline input: False | ||
| Accept wildcard characters: False | ||
| ``` | ||
|
|
||
| ### -Confirm | ||
| Prompts you for confirmation before running the cmdlet. | ||
|
|
||
| ```yaml | ||
| Type: System.Management.Automation.SwitchParameter | ||
| Parameter Sets: (All) | ||
| Aliases: cf | ||
|
|
||
| Required: False | ||
| Position: Named | ||
| Default value: None | ||
| Accept pipeline input: False | ||
| Accept wildcard characters: False | ||
| ``` | ||
|
|
||
| ### CommonParameters | ||
| This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). | ||
|
|
||
| ## INPUTS | ||
|
|
||
| ## OUTPUTS | ||
|
|
||
| ### [PSCustomObject] Returns revert operation results with success status and details. | ||
| ## NOTES | ||
|
|
||
| ## RELATED LINKS | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| function Build-MigrationDescription { | ||
| <# | ||
| .SYNOPSIS | ||
| Builds or updates a migration description object for the device. | ||
|
|
||
| .DESCRIPTION | ||
| Creates a standardized description array with user migration status. | ||
| Handles both creating new descriptions and updating existing ones. | ||
|
|
||
| .PARAMETER UserSID | ||
| The SID of the user being migrated. | ||
|
|
||
| .PARAMETER MigrationUsername | ||
| The username of the user being migrated. | ||
|
|
||
| .PARAMETER StatusMessage | ||
| The status message to record. | ||
|
|
||
| .PARAMETER Percent | ||
| The progress percentage (or "ERROR" for failures). | ||
|
|
||
| .PARAMETER LocalPath | ||
| The local user profile path. | ||
|
|
||
| .PARAMETER authMethod | ||
| The authentication method used for reporting. | ||
| #> | ||
| param( | ||
|
|
||
| [Parameter(Mandatory = $true)] | ||
| [string]$UserSID, | ||
|
|
||
| [Parameter(Mandatory = $true)] | ||
| [string]$MigrationUsername, | ||
|
|
||
| [Parameter(Mandatory = $true)] | ||
| [string]$StatusMessage, | ||
|
|
||
| [Parameter(Mandatory = $true)] | ||
| [string]$Percent, | ||
|
|
||
| [Parameter(Mandatory = $false)] | ||
| [string]$LocalPath, | ||
|
|
||
| [Parameter(Mandatory = $false)] | ||
| [string]$authMethod | ||
| ) | ||
|
|
||
| # Determine the status value based on percent | ||
| $statusValue = if ($Percent -eq "ERROR") { | ||
| "Failed" | ||
| } elseif ($Percent -eq "100%") { | ||
| "Completed" | ||
| } else { | ||
| "InProgress" | ||
| } | ||
|
|
||
| # determine the auth method | ||
| switch ($authMethod) { | ||
| "systemcontextapi" { | ||
| # get the systemDescription with system context api | ||
| $sysContextResult = Invoke-SystemContextAPI -Method GET -Endpoint 'Systems' | ||
| $ExistingDescription = $sysContextResult.description | ||
| } | ||
| "apikey" { | ||
| # get the systemDescription with api key | ||
| $apiKeyResult = Invoke-SystemAPI -JcApiKey $script:JumpCloudAPIKey -jcOrgID $script:JumpCloudOrgID -systemId $script:validatedSystemID -method "GET" | ||
| $ExistingDescription = $apiKeyResult.description | ||
| } | ||
| "none" { | ||
| # if no auth method, exit function return null | ||
| Write-ToLog -Message "Error fetching existing description: $_" -Level Warning | ||
| return $null | ||
| } | ||
| } | ||
| # Initialize or update description array | ||
| if (-not [string]::IsNullOrEmpty($ExistingDescription)) { | ||
| try { | ||
| $description = $ExistingDescription | ConvertFrom-Json | ||
| # Ensure it's always an array | ||
| if ($description -isnot [array]) { $description = @($description) } | ||
| # find the userSID in the existing description | ||
| $foundUser = $description | Where-Object { $_.sid -eq $UserSID } | ||
| if ($foundUser) { | ||
| # only update the message and status | ||
| $foundUser.msg = $StatusMessage | ||
| $foundUser.st = $statusValue | ||
| } else { | ||
| # User not found in existing description, add new entry | ||
| $description += [PSCustomObject]@{ | ||
| sid = $UserSID | ||
| un = $MigrationUsername | ||
| localPath = if ($LocalPath) { $LocalPath.Replace('\', '/') } else { $null } | ||
| msg = $StatusMessage | ||
| st = $statusValue | ||
| uid = $null | ||
| lastLogin = $null | ||
| } | ||
| } | ||
| } catch { | ||
| Write-ToLog -Message "Error parsing existing system description JSON: $_" -Level Warning | ||
| # Fall through to create new description | ||
| $description = $null | ||
| } | ||
| } | ||
| # Create new description if not already initialized - always as array | ||
| if (-not $description) { | ||
| $description = @([PSCustomObject]@{ | ||
| sid = $UserSID | ||
| un = $MigrationUsername | ||
| localPath = if ($LocalPath) { $LocalPath.Replace('\', '/') } else { $null } | ||
| msg = $StatusMessage | ||
| st = $statusValue | ||
| uid = $null | ||
| lastLogin = $null | ||
| }) | ||
| } | ||
| # Ensure return is always an array (use unary comma for PowerShell 5.1 compatibility) | ||
| return @(, $description) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parameter descriptions contain placeholder text '{{ Fill ... Description }}' that should be replaced with actual documentation for the 'form', 'UserName', and 'ProfileSize' parameters.