?
Solved

PowerShell script

Posted on 2014-09-10
7
Medium Priority
?
245 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 Admins - 7 Day Trial

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 2000 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
Uncontrolled local administrators groups within any organization pose a huge security risk. Because these groups are locally managed it becomes difficult to audit and maintain them.
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 …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

801 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