omcmonitor
asked on
Script to move a computer object and add to specified groups.
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,
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,
ASKER
Sorry for my lack of knowledge, is this a vb script?
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?
This is powershell.
what Operating system will you be using to execute this?
ASKER
Well we all run windows 7. So that should work out just fine! Ill go test it out!
great.
you will want to install RSAT if you dont have it already.
http://www.microsoft.com/en-us/download/details.aspx?id=7887
you will want to install RSAT if you dont have it already.
http://www.microsoft.com/en-us/download/details.aspx?id=7887
ASKER
Yep I have that installed for sure. I can get the others setup with it.
ASKER
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?
Currently, does it just look through the entire directory?
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
import-module activedirectory
$computername = read-host Enter Computer Name
get-adcomputer $computername -searchbase "OU=Computers,DC=Domain,DC
add-adgroupmember "Group1" -members $computername
add-adgroupmember "Group2" -members $computername
add-adgroupmember "Group3" -members $computername
ASKER
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
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
ASKER
Now after this
I just get the following prompt with the blinking cursor after it.
get-adcomputer -searchbase "OU=Computers,DC=Domain,DC=Org" -filter {name -eq $computername}| move-adobject -targetpath "OU=Destination,DC=Test,Dc=Domain,DC=com
I just get the following prompt with the blinking cursor after it.
>>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
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
add-adgroupmember "Group1" -members $computername
add-adgroupmember "Group2" -members $computername
add-adgroupmember "Group3" -members $computername