Solved

Powershell script to check Check ProtectedFromAccidentalDeletion status fron input file

Posted on 2013-10-29
6
1,043 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
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 transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

758 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