have a great 2013. I am getting my hands wet on my first PS Script and I am stuck on a very common error, the “Unexpected Token” error. I’ve searched the internet, but could not find an answer, so please help me out.
If ($_.Voorvoegsel.Trim() -ieq "") {
$dn = $_.Voornaam.Trim() + " "
$dn += $_.Achternaam.Trim()
$email = $_.Voornaam.substring(0,1).ToLower() + "."
$email+= $_.Achternaam.Trim().ToLower() + "@test.nl
} Else {
$dn = $_.Voornaam.Trim() + " "
$dn += $_.Voorvoegsel.Trim() + " "
$dn += $_.Achternaam.Trim()
$email = $_.Voornaam.substring(0,1).ToLower() + "."
$email += $_.Voorvoegsel.Replace(" ","").ToLower()
$email += $_.Achternaam.Trim().ToLower() + "@test.nl
}
The strange thing is that it errors on the $_.Voorvoegsel variable in the else statement:
Unexpected token '
$dn += $_.Voorvoegsel.Trim()
$dn += ' in expression or statement.
At C:\Users\Public\Documents\PSImportTest.ps1:42 char:12
+ $dn = $_ <<<< .Voornaam.Trim() + " "
+ CategoryInfo : ParserError: (
$dn += $_....m()
$dn += :String) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken
Anyone out there who sees what my blind spot is here?
It may be that you are missing an end quote on line 5:
It looks like you also may be missing one on line 12. Powershell may think the rest of the code, until the next quote character, is part of your string literal.