Solved

Move AD objects listed in text file from PS script

Posted on 2013-06-04
9
1,390 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 500 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

739 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