I am attaching a script so far that I have had a colleague basically help me write… Although he did substantially most of the work. I am very new to this but looking to finish up the end of this script. Any help would be greatly appreciated!
I’m specifically looking for help with Region 4 and below, but any suggestions to a new scripter would be great!
##Mission: Create user supplied computer objects in referenced OU
#region (1) Create static variables (Set Variables)
workstation ou
$workstationou=“ou=regional,ou=workstations,dc=XXXX,dc=global”
lab
$labou=“ou=lab,ou=servers,dc=XXXX,dc=global”
server
$serverou=“ou=regional,ou=servers,dc=XXXX,dc=global”
mfg machines ou
$mfgou=“ou=mfg,ou=servers,dc=XXXX,dc=global”
#endregion
#region (2) Ask the user for input (Get Variables)
#new computer name
$newsystem= read-host “Please enter the system name.”
#Site (USA,USD,USJ)
$site= Read-Host “Please enter the XXXX site code.”
#Region (USA,MY,UK,etc)
$region=Read-Host “Please enter the region code.”
#Type (Lab,Server,Workstation,Mfg,etc)
$systemtype=Read-Host “Please enter the system type.”
#endregionmore
#region (3) Build OU path based on input from (2) Getting variables
#Test type of PC and use appropriate base OU variable
#ex.OU=USA,OU=USA,OU=regional,OU=servers,DC=XXXX,DC=global
if ($systemtype -eq “lab”)
{$adlocation=(“OU=” + $site + “,OU=” + $region + “,” + $labou)}
if ($systemtype -eq “server”)
{$adlocation=(“OU=” + $site + “,OU=” + $region + “,” + $serverou)}
if ($systemtype -eq “workstation”)
{$adlocation=(“OU=” + $site + “,OU=” + $region + “,” + $workstationou)}
if ($systemtype -eq “mfg”)
{$adlocation=(“OU=” + $site + “,OU=” + $region + “,” + $mfgou)}
Write-Host $adlocation
#create new string from multiple strings (concatenate the variables from step 2 and 1)
#endregion
#region (4) Verify computer name
#Test if the computername is not like sitecode-*
$learn=$site + “-*”
if ($newsystem -like $learn)
{
} else {
#prepend site code to computername
$newsystem=($site + "-" + $newsystem)}
Write-Host $newsystem
#Test if there are duplicates in AD
$duplicate=Get-ADComputer -filter 'name -eq $newsystem'
if ($duplicate)
{
}
#endregion
#Create computer name in proper OU
#Use New-adcomputer
#end script