-
-
Notifications
You must be signed in to change notification settings - Fork 18
feat: remove protection flag before disabling computers #31
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
base: master
Are you sure you want to change the base?
Conversation
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.
Pull request overview
This PR adds functionality to automatically remove the ProtectedFromAccidentalDeletion flag from computer objects before performing disable operations, preventing manual intervention when this flag would otherwise block automated cleanup processes.
- Introduces a new
RemoveProtectedFromAccidentalDeletionFlagswitch parameter toDisable-WinADComputer - Implements protection flag removal logic with proper error handling and event logging
- Adds Pester test coverage for the new flag removal functionality
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| Tests/Disable-WinADComputer.Tests.ps1 | New test file validating that the protection flag is removed when requested |
| Public/Invoke-ADComputersCleanup.ps1 | Updated parameter documentation to clarify flag removal applies to disable, move, and delete operations |
| Private/Request-ADComputersDisable.ps1 | Passes the RemoveProtectedFromAccidentalDeletionFlag parameter to both disable and move operations |
| Private/Disable-WinADComputer.ps1 | Implements flag removal logic before disabling computers, with try-catch error handling and event logging |
| Examples/DeleteComputersWithMoveAndEmail.ps1 | Demonstrates usage of the new flag removal parameter in a real-world scenario |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if ($Computer.Enabled -eq $true) { | ||
| if ($RemoveProtectedFromAccidentalDeletionFlag -and $Computer.ProtectedFromAccidentalDeletion) { | ||
| try { | ||
| Write-Color -Text "[i] Removing protected from accidental deletion flag for computer ", $Computer.DistinguishedName, ' DN: ', $Computer.DistinguishedName, ' Enabled: ', $Computer.Enabled, ' Operating System: ', $Computer.OperatingSystem, ' LastLogon: ', $Computer.LastLogonDate, " / " , $Computer.LastLogonDays , ' days, PasswordLastSet: ', $Computer.PasswordLastSet, " / ", $Computer.PasswordLastChangedDays, " days" -Color Yellow, Green, Yellow, Green, Yellow, Green, Yellow, Green, Yellow, Green, Yellow, Green, Yellow, Green |
Copilot
AI
Nov 23, 2025
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.
The message contains redundant information. The text includes both "computer " and "DN: " with the same value (DistinguishedName) displayed twice. Consider removing one of these redundant parts to make the message clearer. For example:
Write-Color -Text "[i] Removing protected from accidental deletion flag for computer ", $Computer.SamAccountName, ' DN: ', $Computer.DistinguishedName, ' Enabled: ', $Computer.Enabled, ' Operating System: ', $Computer.OperatingSystem, ' LastLogon: ', $Computer.LastLogonDate, " / " , $Computer.LastLogonDays , ' days, PasswordLastSet: ', $Computer.PasswordLastSet, " / ", $Computer.PasswordLastChangedDays, " days" -Color Yellow, Green, Yellow, Green, Yellow, Green, Yellow, Green, Yellow, Green, Yellow, Green, Yellow, Green| Write-Color -Text "[i] Removing protected from accidental deletion flag for computer ", $Computer.DistinguishedName, ' DN: ', $Computer.DistinguishedName, ' Enabled: ', $Computer.Enabled, ' Operating System: ', $Computer.OperatingSystem, ' LastLogon: ', $Computer.LastLogonDate, " / " , $Computer.LastLogonDays , ' days, PasswordLastSet: ', $Computer.PasswordLastSet, " / ", $Computer.PasswordLastChangedDays, " days" -Color Yellow, Green, Yellow, Green, Yellow, Green, Yellow, Green, Yellow, Green, Yellow, Green, Yellow, Green | |
| Write-Color -Text "[i] Removing protected from accidental deletion flag for computer ", $Computer.SamAccountName, ' DN: ', $Computer.DistinguishedName, ' Enabled: ', $Computer.Enabled, ' Operating System: ', $Computer.OperatingSystem, ' LastLogon: ', $Computer.LastLogonDate, " / " , $Computer.LastLogonDays , ' days, PasswordLastSet: ', $Computer.PasswordLastSet, " / ", $Computer.PasswordLastChangedDays, " days" -Color Yellow, Green, Yellow, Green, Yellow, Green, Yellow, Green, Yellow, Green, Yellow, Green, Yellow, Green |
Summary
Testing
pwsh -NoLogo -NoProfile -Command "Invoke-Pester -Path ./Tests"pwsh -NoLogo -NoProfile -File Build/Build-Module.ps1(fails: The term 'Invoke-ModuleBuild' is not recognized)https://chatgpt.com/codex/tasks/task_e_689510850fdc832ea16b76d72934acb7