We help IT Professionals succeed at work.
Get Started

Powershell script help - How to combine values

Last Modified: 2015-03-03
Long story short, I'm crafting a script to create a new domain user.. part of my script adds values like Description, and proxy address.. but to help us add the correct proxyaddress that will work with our O365 tenant I need to combine teh username with a custom string and I'm hitting a brick wall with the syntax.

Here's what I have:

$theOU = read-host "Enter the OU name"
$Surname = read-Host "Enter the surname"
$GivenName = read-host "Enter first name"
$DisplayName = "$Surname, $GivenName"
$Password = "December1"
$name = $GivenName.substring(0,1)+$Surname
$proxyaddress = read-host "Enter the proxy address in full"
#$txtBoxTelephone = read-host "Enter phone #"
$DomainProxyAddress = $GivenName.substring(0,1)+$Surname <------------------------------------
$txtBoxDescription = read-host "Enter persons description"
Import-Module activedirectory
import-module servermanager

	$myOU = Get-AdOrganizationalUnit -Filter "Name -eq '$theOU'" -Searchbase 'OU=People,DC=domain,DC=org'
Get-ADuser  -filter * -Properties ProxyAddresses|?{$_.proxyaddresses -contains $proxyaddress}
	$found=Get-ADuser  -filter * -Properties ProxyAddresses|
        $_.proxyaddresses | 
             Where-Object{ $_ -eq $ProxyAddress }}

	write-host "ProxyAddress Exists, Change username to something unique!"
get-aduser -filter * -properties $proxyaddress
pause 5
	else {
	write-host "ProxyAddress Not Found!"
Pause 5


write-host	$myou
write-host $name
New-ADUser -path $myOU -samaccountname $name -name $displayname -DisplayName $DisplayName -Surname $Surname -givenname $givenname -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -force) -enabled:$false
set-aduser $name -properties proxyaddresses $proxyaddress
set-aduser $name -properties proxyaddresses 	
get-aduser $name

Open in new window

$DomainProxyAddress is the line I'm editing currently.  I basically need a secondary proxy address like:

Tester, Adam

I do not know the correct syntax to create this string... Help?
Watch Question
Top Expert 2007
This problem has been solved!
Unlock 1 Answer and 14 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE