Need help getting Unexpected token '}' an expresstion or statment
-
Sunday, February 05, 2012 5:31 PM
I am working in the MOAC lab and have hit a Snag
getting Unexpected token '}' an expresstion or statment in statment
Import-CSV `c:\Project58members.csv'| foreach-object -process {Set mailbox -identity $_.Identity -managedfoldermailboxpolicy `Project58 Managed folder policy'} <<<<
any suggestions
Answers
-
Sunday, February 05, 2012 7:01 PM
Try this instead:
Import-CSV c:\Project58members.csv| foreach-object -process {Set mailbox -identity $_.Identity -managedfoldermailboxpolicy 'Project58 Managed folder policy'}
It looks like you were using apostrophes instead of single quotes.
Rich Prescott | Infrastructure Architect, Windows Engineer and PowerShell blogger | MCITP, MCTS, MCP
Engineering Efficiency
@Rich_Prescott
Windows System Administration tool 2.0
AD User Creation tool
In both quoted strings the OP used a back-tick for the opening quote and a single-quote for the closing quote:Import-CSV `c:\Project58members.csv'| foreach-object -process {Set mailbox -identity $_.Identity -managedfoldermailboxpolicy `Project58 Managed folder policy'}
he only quoted string in the above is therefore this:
'| foreach-object -process {Set mailbox -identity $_.Identity -managedfoldermailboxpolicy `Project58 Managed folder policy'
reducing the statement to this:
Import-CSV `c:\Project58members.csv'whatever'}
In which it is easier to see that the "}" was unexpected.
- Marked As Answer by Bartek BielawskiModerator Sunday, February 05, 2012 9:18 PM
All Replies
-
Sunday, February 05, 2012 5:37 PMModerator
Try this instead:
Import-CSV c:\Project58members.csv| foreach-object -process {Set mailbox -identity $_.Identity -managedfoldermailboxpolicy 'Project58 Managed folder policy'}
It looks like you were using apostrophes instead of single quotes.
Rich Prescott | Infrastructure Architect, Windows Engineer and PowerShell blogger | MCITP, MCTS, MCP
Engineering Efficiency
@Rich_Prescott
Windows System Administration tool 2.0
AD User Creation tool- Proposed As Answer by BigteddyMicrosoft Community Contributor Sunday, February 05, 2012 6:00 PM
-
Sunday, February 05, 2012 7:01 PM
Try this instead:
Import-CSV c:\Project58members.csv| foreach-object -process {Set mailbox -identity $_.Identity -managedfoldermailboxpolicy 'Project58 Managed folder policy'}
It looks like you were using apostrophes instead of single quotes.
Rich Prescott | Infrastructure Architect, Windows Engineer and PowerShell blogger | MCITP, MCTS, MCP
Engineering Efficiency
@Rich_Prescott
Windows System Administration tool 2.0
AD User Creation tool
In both quoted strings the OP used a back-tick for the opening quote and a single-quote for the closing quote:Import-CSV `c:\Project58members.csv'| foreach-object -process {Set mailbox -identity $_.Identity -managedfoldermailboxpolicy `Project58 Managed folder policy'}
he only quoted string in the above is therefore this:
'| foreach-object -process {Set mailbox -identity $_.Identity -managedfoldermailboxpolicy `Project58 Managed folder policy'
reducing the statement to this:
Import-CSV `c:\Project58members.csv'whatever'}
In which it is easier to see that the "}" was unexpected.
- Marked As Answer by Bartek BielawskiModerator Sunday, February 05, 2012 9:18 PM
-
Sunday, February 05, 2012 8:18 PM
I think this might make it a bit easier to see.
$csvfile="c:\Project58members.csv" $mbpolicy="Project58 Managed folder policy" Import-CSV $csvfile | foreach-object -process { Set mailbox -identity $_.Identity -managedfoldermailboxpolicy $mbpolicy }
This way the quotes are not hidden in the lines.
The issue is use of back-ticks instead of single quotes (apostrophes). Back-ticks are only used to escape a character in a string or as a line continuation character. The behavior of the back-tick in this scenario is unpredictable or not easily predictable.
Stay away from back-ticks in static strings.
Al's example is also easy to see.
¯\_(ツ)_/¯- Edited by jrvMicrosoft Community Contributor Sunday, February 05, 2012 8:20 PM