Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Powershell to Disable "Protect from Accidental Deletion" on List of computers

$
0
0

Hello, I need some help please

I used this script in a LAB environment with ADDS on WinServer 2012 R2 successfully.

$Computers = get-content C:\Users\Administrator\Desktop\Servers.txt
ForEach ($Computer In $Computers) {
    $DN = (Get-ADComputer -LDAPFilter "(Name=*$Computer*)").distinguishedName
    If ($DN) {Set-ADObject -Identity $DN -ProtectedFromAccidentalDeletion $True}
}

When running the same script in the production environment there was a conversion failure stating that the Method is not supported

Set-ADObject : Cannot convert 'System.Object[]' to the type 'Microsoft.ActiveDirectory.Management.ADObject' required by parameter 'Identity'. Specified method is not supported.
At line:4 char:38
+     If ($DN) {Set-ADObject -Identity $DN -ProtectedFromAccidentalDele ...


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>