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

x
?
Solved

Move AD objects listed in text file from PS script

Posted on 2013-06-04
9
Medium Priority
?
1,466 Views
Last Modified: 2013-06-04
Hey Experts!!  I am crafting a way for inactive/dormant AD objects to be moved from their OU to an "Inactive" OU.  The objects would be moved if they are listed in a text file using Powershell's Move-ADObject.  Can anyone provide the command and syntax for this?  Thanks Experts.
0
Comment
Question by:samiam41
[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
  • 5
  • 2
  • 2
9 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 total points
ID: 39219156
Try..
GC C:\User.txt | Get-ADUser | Move-ADObject -TargetPath 'OU=Inactive,DC=Fabrikam,Dc=com'

Open in new window

Input file format..
SaraDavis
Subsun
Sunsub

Open in new window

0
 
LVL 22

Expert Comment

by:Haresh Nikumbh
ID: 39219182
0
 
LVL 9

Author Comment

by:samiam41
ID: 39219263
Thank you.  Testing now.
0
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.

 
LVL 9

Author Comment

by:samiam41
ID: 39219679
Not sure what I am doing wrong here but I keep getting this error:

The term 'Get-ADUser' is not recognized as the name of a cmdlet, function, scri
pt file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:39
+ GC c:\tools\staleadpc.log | Get-ADUser <<<<  | Move-ADObject -targetpath 'ou=
x,ou=xx,dc=xxx,dc=xxxx,dc=xxxx,dc=xy'
    + CategoryInfo          : ObjectNotFound: (Get-ADUser:String) [], CommandN
   otFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\Users\me> GC c:\tools\staleadpc.log | Get-ADUser | Move-ADObject -
targetpath 'ou=x,ou=xx,dc=xxx,dc=xxxx,dc=xxxx,dc=xy'

Open in new window


I checked my PS version and got this:
CLRVersion                     2.0.50727.5466
BuildVersion                   6.1.7601.17514
PSVersion                      2.0
WSManStackVersion              2.0
PSCompatibleVersions           {1.0, 2.0}
SerializationVersion           1.1.0.1
PSRemotingProtocolVersion      2.1

Thoughts?
0
 
LVL 9

Author Comment

by:samiam41
ID: 39219713
I ran the Get-Module -Listavailable

Manifest   ActiveDirectory           {}
Manifest   AppLocker                 {}
Manifest   BitsTransfer              {}
Manifest   GroupPolicy               {}
Manifest   PSDiagnostics             {}
Manifest   TroubleshootingPack       {}
0
 
LVL 9

Author Comment

by:samiam41
ID: 39219727
Never mind, I just ran Import-Module ActiveDirectory and I got a new error so that other error has been resolved..  Updates coming up.
0
 
LVL 9

Author Closing Comment

by:samiam41
ID: 39219751
Works just as I needed!  Thanks.
0
 
LVL 22

Expert Comment

by:Haresh Nikumbh
ID: 39219756
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39219818
Nice!!..
The term 'Get-ADUser' is not recognized as the name of a cmdlet
normally means ActiveDirectory module is not loaded so PowerShell is not recognizing the commands Get-ADUser or Move-ADObject.
0

Featured Post

Are You Ready for GDPR?

With the GDPR deadline set for May 25, 2018, many organizations are ill-prepared due to uncertainty about the criteria for compliance. According to a recent WatchGuard survey, a staggering 37% of respondents don't even know if their organization needs to comply with GDPR. Do you?

Question has a verified solution.

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

Uncontrolled local administrators groups within any organization pose a huge security risk. Because these groups are locally managed it becomes difficult to audit and maintain them.
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…
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 …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 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