Solved

PowerShell script

Posted on 2014-09-10
7
232 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Exchange 2010 - securing email internally? 1 41
AD LDAP LDS 3 48
Adding a continue option in a script 9 20
exchange, active directory 8 28
Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
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 …

920 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

15 Experts available now in Live!

Get 1:1 Help Now