Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Move AD objects listed in text file from PS script

Posted on 2013-06-04
9
Medium Priority
?
1,497 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 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Question has a verified solution.

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

Let's recap what we learned from yesterday's Skyport Systems webinar.
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
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 …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

773 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