Solved

PowerShell script

Posted on 2014-09-10
7
229 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 28

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
 
LVL 28

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 28

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

Join & Write a Comment

Suggested Solutions

Synchronize a new Active Directory domain with an existing Office 365 tenant
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
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 tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now