Solved

PowerShell script

Posted on 2014-09-10
7
243 Views
Last Modified: 2014-09-26
All,

     I am in desperate need of help. I need to have a powershell script that first can add multiple  workstations to the domain, then name the workstations and move the computer accounts to the proper OU in AD. Thanks
0
Comment
Question by:Lancecooly
[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
  • 4
  • 3
7 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 40316058
What version of powershell will you be working with ?

This would help to determine the potential solution.
0
 

Author Comment

by:Lancecooly
ID: 40316596
Name                           Value
----                           -----
WSManStackVersion              3.0
PSCompatibleVersions           {1.0, 2.0, 3.0}
SerializationVersion           1.1.0.1
BuildVersion                   6.2.9200.16398
PSVersion                      3.0
CLRVersion                     4.0.30319.1022
PSRemotingProtocolVersion      2.2
0
 

Author Comment

by:Lancecooly
ID: 40316709
Will powershell create a duplicate record in DNS like netdom does?
0
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
LVL 29

Accepted Solution

by:
becraig earned 500 total points
ID: 40318465
We will do a look-up for the name before we create it.

$ErrorActionPreference = "SilentlyContinue"
$domain =  Read-Host -Prompt "Please Enter your Domain"
$user = Read-Host -Prompt "Please Enter your username"
$username = "$domain\$user" 
$password = Read-Host -Prompt "Enter password for $user" -AsSecureString
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
$destou = Read-Host "Please Enter the OU to move servers to (e.g. ou=something,dc=mydomain,dc=local)"
import-module ac*
gc c:\computerlist.txt | % {
$computer = $_
Get-ADComputer $computer | Move-ADObject -TargetPath $destou
Write-host "Adding $computer to $domain..."
Add-Computer -DomainName $domain -Credential $credential
write-host "Renaming $computer..."
$dname = [System.Net.DNS]::GetHostAddresses($computer)[0].IpaddressToString
if ($dname -eq $null) 
{
$nuname =Read-Host "Please Enter the new computer name"
Rename-Computer -ComputerName $computer -NewName $nuname -DomainCredential $credential -Force -Restart
}
else 
{
write-host "$nuame is already registered on the network... `nProceeding with next server..." -ForegroundColor RED;
}
                            }

Open in new window

0
 

Author Comment

by:Lancecooly
ID: 40322768
I see where the ps calls gc c:\computerlist.txt | % { Is this the same list that will be called for renaming the computer? Thanks
0
 
LVL 29

Expert Comment

by:becraig
ID: 40323018
The script will actually prompt you for each new name in the window, if you want to pipe in both values we can make a change and create a csv with old name in one column and new name in the other.

I would have to make a minor change to accommodate this.
0
 

Author Comment

by:Lancecooly
ID: 40325026
Yes that will be great. I will have a large list of old and new computer names. Just so I am clear, if the old name is in DNS when I run ps will DNS update the new name information on the old record or will DNS create a new record? This will give me two DNS records for one IP if DNS does not update the record. Is it just good house cleaning to delete the old record with that IP. Then run the new ps script. Thanks
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

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 …
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
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 to another domain controller. Log onto the new domain controller with a user account t…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

717 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