Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Powershell script to check Check ProtectedFromAccidentalDeletion status fron input file

Posted on 2013-10-29
6
Medium Priority
?
1,183 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 2000 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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Group policies can be applied selectively to specific devices with the help of groups. Utilising this, it is possible to phase-in group policies, over a period of time, by randomly adding non-members user or computers at a set interval, to a group f…
A bad practice commonly found during an account life cycle is to set its password to an initial, insecure password. The Password Reset Tool was developed to make the password reset process easier and more secure.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

670 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