Solved

Powershell script to check Check ProtectedFromAccidentalDeletion status fron input file

Posted on 2013-10-29
6
1,057 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
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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
A brief introduction to what I consider to be the best editor for PowerShell.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

947 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now