Solved

Powershell script to check Check ProtectedFromAccidentalDeletion status fron input file

Posted on 2013-10-29
6
1,070 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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 is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
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 …

786 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