WWWWWWWWWP
WWWWWWWWWP

Reputation: 45

Syntax error Powershell create list SharePoint

I have some syntax problem in my script, I have this error :

enter image description here

Unexpected token '

This is the code:

if ($bCreate_Lists)
{

CreateList $webURL 100 "CatMissions" "Catégories de mission" "Catégories de mission" "Catégorie"'
@()'
@()

CreateList $webURL 100 "DomainesEtudes" "Domaines d études" "Domaines d études" "Domaine d étude"'
@("AN,Anglais,Text","ESP,Espagnol,Text","POR,Portugais,Text","L1,Langue 1,Text","L2,Langue 2,Text")'
@('
    "Domaine d étude_1|Domaine d étude_1_EN|Domaine d étude_1_ESP|Domaine d étude_1_POR|Domaine d étude_1_L1|Domaine d étude_1_L2"'
    ,"Domaine d étude_2|Domaine d étude_2_EN|Domaine d étude_2_ESP|Domaine d étude_2_POR|Domaine d étude_2_L1|Domaine d étude_2_L2"'
    ,"Domaine d étude_3|Domaine d étude_3_EN|Domaine d étude_3_ESP|Domaine d étude_3_POR|Domaine d étude_3_L1|Domaine d étude_3_L2"'
    ,"Domaine d étude_4|Domaine d étude_4_EN|Domaine d étude_4_ESP|Domaine d étude_4_POR|Domaine d étude_4_L1|Domaine d étude_4_L2"'
    ,"Domaine d étude_5|Domaine d étude_5_EN|Domaine d étude_5_ESP|Domaine d étude_5_POR|Domaine d étude_5_L1|Domaine d étude_5_L2"'
)

Can you help me?

Upvotes: 0

Views: 48

Answers (2)

dan-gph
dan-gph

Reputation: 16909

In my opinion, it's best to avoid line continuation characters because they can be confusing. It's best just to use intermediate variables:

CreateList $webURL 100 "CatMissions" "Catégories de mission" "Catégories de mission" "Catégorie" @() @()

$list1 = @("AN,Anglais,Text","ESP,Espagnol,Text","POR,Portugais,Text","L1,Langue 1,Text","L2,Langue 2,Text")

$list2 = @(
    "Domaine d étude_1|Domaine d étude_1_EN|Domaine d étude_1_ESP|Domaine d étude_1_POR|Domaine d étude_1_L1|Domaine d étude_1_L2",
    "Domaine d étude_2|Domaine d étude_2_EN|Domaine d étude_2_ESP|Domaine d étude_2_POR|Domaine d étude_2_L1|Domaine d étude_2_L2",
    "Domaine d étude_3|Domaine d étude_3_EN|Domaine d étude_3_ESP|Domaine d étude_3_POR|Domaine d étude_3_L1|Domaine d étude_3_L2",
    "Domaine d étude_4|Domaine d étude_4_EN|Domaine d étude_4_ESP|Domaine d étude_4_POR|Domaine d étude_4_L1|Domaine d étude_4_L2",
    "Domaine d étude_5|Domaine d étude_5_EN|Domaine d étude_5_ESP|Domaine d étude_5_POR|Domaine d étude_5_L1|Domaine d étude_5_L2"
)

CreateList $webURL 100 "DomainesEtudes" "Domaines d études" "Domaines d études" "Domaine d étude" $list1 $list2

Upvotes: 1

jessehouwing
jessehouwing

Reputation: 114887

It's probably failing on @()', since it has an unbalanced single quote. I suspect you're trying to wrap the long line, which requires the use of the back-tick ` preceded by a space:

So instead of:

CreateList $webURL 100 "CatMissions" ... "Catégorie"'
@()'

Use:

CreateList $webURL 100 "CatMissions" ... "Catégorie" `
@() `

Note: The space before the ` is important!

The ` ~ character usually sits on the upper left corner of the keyboard of a US keyboard layout.

enter image description here

Given the error message you posted is in French, I suspect you're using the French keyboard layout, the key you're looking for is probably the one highlighted here:

enter image description here

Note, by placing the , on the previous line, Powershell will know you want to wrap the line and you won't need to use the line-continuation marker on those lines:

CreateList $webURL 100 "DomainesEtudes" "Domaines d études" "Domaines d études" "Domaine d étude" `
@("AN,Anglais,Text","ESP,Espagnol,Text","POR,Portugais,Text","L1,Langue 1,Text","L2,Langue 2,Text") `
@(
    "Domaine d étude_1|Domaine d étude_1_EN|Domaine d étude_1_ESP|Domaine d étude_1_POR|Domaine d étude_1_L1|Domaine d étude_1_L2",
    "Domaine d étude_2|Domaine d étude_2_EN|Domaine d étude_2_ESP|Domaine d étude_2_POR|Domaine d étude_2_L1|Domaine d étude_2_L2",
    "Domaine d étude_3|Domaine d étude_3_EN|Domaine d étude_3_ESP|Domaine d étude_3_POR|Domaine d étude_3_L1|Domaine d étude_3_L2",
    "Domaine d étude_4|Domaine d étude_4_EN|Domaine d étude_4_ESP|Domaine d étude_4_POR|Domaine d étude_4_L1|Domaine d étude_4_L2",
    "Domaine d étude_5|Domaine d étude_5_EN|Domaine d étude_5_ESP|Domaine d étude_5_POR|Domaine d étude_5_L1|Domaine d étude_5_L2"
)

If you don't put the , on the previous line, you'll need to replace the ' on all other instances as well:

enter image description here

Upvotes: 1

Related Questions