Solved

Move AD objects listed in text file from PS script

Posted on 2013-06-04
9
1,292 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
  • 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
 
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

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
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 steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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…

743 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

10 Experts available now in Live!

Get 1:1 Help Now