Solved

Move AD objects listed in text file from PS script

Posted on 2013-06-04
9
1,355 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
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 …
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 …

820 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