Solved

PowerShell script

Posted on 2014-09-10
7
239 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
This article outlines the process to identify and resolve account lockout in an Active Directory environment.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

830 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