Solved

Powershell script to check Check ProtectedFromAccidentalDeletion status fron input file

Posted on 2013-10-29
6
1,149 Views
Last Modified: 2013-10-29
Hi

We have a script now that will  disable peoples user account and moved them to a specific OU based on an input csv file,

An issue we have encountered is that some of our users have ProtectedFromAccidentalDeletion enabled, This then stops them being moved.

Before we run the script to disable I would like a script that will use the same input file and give me the output of the users ProtectedFromAccidentalDeletion status so I can identify the users.

Thanks
0
Comment
Question by:ncomper
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 22

Expert Comment

by:Joseph Moody
ID: 39608822
You could take it a step further and remove the permission for those accounts before moving the users:

http://deployhappiness.com/deleting-protected-objects/
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 39608856
Try..
GC c:\User.txt | Get-ADUser -Properties * | ? {$_.ProtectedFromAccidentalDeletion -ne $false}

Open in new window

User.txt format..
UserA
UserB
UserC

Open in new window

0
 
LVL 57

Expert Comment

by:Mike Kline
ID: 39608905
Another way of doing it, this will output the samaccountname and portectedfromaccidentaldeltionstatus

import-csv C:\users1.csv | foreach-object {get-aduser -filter * -Properties *} | format-table samaccountname, protectedfromaccidentaldeletion -AutoSize

Open in new window


Thanks

Mike
0
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
LVL 5

Author Comment

by:ncomper
ID: 39609000
Thanks all

If I want to take the CSV file and actually set them to true or false whats the syntax,, I was trying the below but keep getting erros

import-csv c:\scripts\users6.csv | Set-ADobject -ProtectedFromAccidentalDeletion $false

Open in new window


Thanks
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39609027
Try..
import-csv c:\scripts\users6.csv | % {
Set-ADobject (Get-AdUser $_.samaccountname).distinguishedname -ProtectedFromAccidentalDeletion $false
}

Open in new window

Csv format..
samaccountname
UserA
UserB
UserC

Open in new window

0
 
LVL 5

Author Closing Comment

by:ncomper
ID: 39609056
Thanks again
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates probably the easiest way to configure domain-wide tier isolation within Active Directory. If you do not know tier isolation read https://technet.microsoft.com/en-us/windows-server-docs/security/securing-privileged-access/s…
Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question