Skip to content

Conversation

@PrzemyslawKlys
Copy link
Member

Summary

  • add option to clear ProtectedFromAccidentalDeletion before disabling
  • pass flag removal switch through disabling pipeline
  • cover Disable-WinADComputer with Pester test and document flag removal parameter

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

Copy link
Contributor

Copilot AI left a 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 RemoveProtectedFromAccidentalDeletionFlag switch parameter to Disable-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
Copy link

Copilot AI Nov 23, 2025

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
Suggested change
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

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants