?
Solved

Script to move a computer object and add to specified groups.

Posted on 2013-05-16
14
Medium Priority
?
610 Views
Last Modified: 2013-06-16
Hello all,

Im looking for some help creating a script (or finding one) that can be used easily by our workstation support team.

Here is what needs to happen

1. Computer Object gets created in a specified OU - This will be done manually.
2. Workstation Tech starts the script and enters the computer name that was created.
3. Script moves the computer object to a specified OU and adds it to a set of specified security groups.

Thanks again,
0
Comment
Question by:omcmonitor
[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
  • 6
  • 6
14 Comments
 
LVL 7

Expert Comment

by:BT15
ID: 39172400
this asks for an inputed computername. you just need to sub out the distiguished name of the OU that you are moving to and the group names you want to add.

you also need the activedirectory commandlets installed (RSAT)

if you dont have those (or are running XP/server 2003) there are AD commandlets availible from Quest with similar syntax.



import-module activedirectory

$computername = read-host Enter Computer Name

get-adcomputer $computername | move-adobject -targetpath "OU=Destination,DC=Test,Dc=Domain,DC=com

add-adgroupmember "Group1" -members $computername
add-adgroupmember "Group2" -members $computername
add-adgroupmember "Group3" -members $computername
0
 

Author Comment

by:omcmonitor
ID: 39172533
Sorry for my lack of knowledge, is this a vb script?
0
 
LVL 7

Expert Comment

by:BT15
ID: 39172553
no need to be sorry. I didnt see that this was given multiple topics.

This is powershell.

what Operating system will you be using to execute this?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:omcmonitor
ID: 39172566
Well we all run windows 7. So that should work out just fine! Ill go test it out!
0
 
LVL 7

Expert Comment

by:BT15
ID: 39172581
great.

you will want to install RSAT if you dont have it already.

http://www.microsoft.com/en-us/download/details.aspx?id=7887
0
 

Author Comment

by:omcmonitor
ID: 39172588
Yep I have that installed for sure. I can get the others setup with it.
0
 

Author Comment

by:omcmonitor
ID: 39172615
Is there a way i can specify the OU that the script looks in initially? say OU=Computers,DC=Domain,DC=Org

Currently, does it just look through the entire directory?
0
 
LVL 7

Expert Comment

by:BT15
ID: 39172761
absolutely

import-module activedirectory

$computername = read-host Enter Computer Name

get-adcomputer $computername -searchbase "OU=Computers,DC=Domain,DC=Org" | move-adobject -targetpath "OU=Destination,DC=Test,Dc=Domain,DC=com

add-adgroupmember "Group1" -members $computername
add-adgroupmember "Group2" -members $computername
add-adgroupmember "Group3" -members $computername
0
 

Author Comment

by:omcmonitor
ID: 39174656
I am running the commands one at a time and get the following error.

Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS U:\> import-module activedirectory
PS U:\> $computername = read-host Enter Computer Name
Enter Computer Name: SEC1ITL004
PS U:\> get-adcomputer $computername -searchbase "OU=Computers Test,DC=Domain,DC=org" | move-adobject -targetpath "OU=Wi
reless Lockdown,OU=Imprivata,OU=Workstations,OU=Devices,OU=Hospital,DC=Domain,DC=org"
Get-ADComputer : A positional parameter cannot be found that accepts argument 'SEC1ITL004'.
At line:1 char:15
+ get-adcomputer <<<<  $computername -searchbase "OU=Computers Test,DC=Domain,DC=org" | move-adobject -targetpath "OU=W
ireless Lockdown,OU=Imprivata,OU=Workstations,OU=Devices,OU=Hospital,DC=olmmed,DC=org"
    + CategoryInfo          : InvalidArgument: (:) [Get-ADComputer], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADComputer

Open in new window

0
 
LVL 7

Expert Comment

by:BT15
ID: 39174854
my appologies. Please try this instead:

import-module activedirectory

$computername = read-host Enter Computer Name

get-adcomputer -searchbase "OU=Computers,DC=Domain,DC=Org"  -filter {name -eq $computername}| move-adobject -targetpath "OU=Destination,DC=Test,Dc=Domain,DC=com

add-adgroupmember "Group1" -members $computername
add-adgroupmember "Group2" -members $computername
add-adgroupmember "Group3" -members $computername

Open in new window

0
 

Author Comment

by:omcmonitor
ID: 39174886
Now after this

get-adcomputer -searchbase "OU=Computers,DC=Domain,DC=Org"  -filter {name -eq $computername}| move-adobject -targetpath "OU=Destination,DC=Test,Dc=Domain,DC=com

Open in new window


I just get the following prompt with the blinking cursor after it.

>>

Open in new window

0
 
LVL 7

Accepted Solution

by:
BT15 earned 2000 total points
ID: 39181687
sorry. its missing a closed quote on that line, which apparently didnt paste.


import-module activedirectory

$computername = read-host Enter Computer Name

get-adcomputer -searchbase "OU=Computers,DC=Domain,DC=Org"  -filter {name -eq $computername}| move-adobject -targetpath "OU=Destination,DC=Test,Dc=Domain,DC=com"

add-adgroupmember "Group1" -members $computername
add-adgroupmember "Group2" -members $computername
add-adgroupmember "Group3" -members $computername

Open in new window

0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 39251080
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Bringing Advanced Authentication to the SMB Market

WatchGuard announces the acquisition of advanced authentication provider, Datablink, with one mission – to bring secure authentication to SMB, mid-market, and distributed enterprises with a cloud-based solution, ideal for resale via their established channel & MSSP community.

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…
Suggested Courses

777 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