将多行文字作为变量粘贴在PowerShell中不起作用

时间:2019-02-03 13:37:59

标签: powershell

我正在尝试将MS Docs中的某些代码粘贴到PowerShell中,该代码用于变量,但是当我粘贴它并按Enter时,什么也没有发生。

以下是变量的代码:

    $site_script = @'
 {
     "$schema": "schema.json",
         "actions": [
             {
                 "verb": "createSPList",
                 "listName": "Customer Tracking",
                 "templateType": 100,
                 "subactions": [
                     {
                         "verb": "SetDescription",
                         "description": "List of Customers and Orders"
                     },
                     {
                         "verb": "addSPField",
                         "fieldType": "Text",
                         "displayName": "Customer Name",
                         "isRequired": false,
                         "addToDefaultView": true
                     },
                     {
                         "verb": "addSPField",
                         "fieldType": "Number",
                         "displayName": "Requisition Total",
                         "addToDefaultView": true,
                         "isRequired": true
                     },
                     {
                         "verb": "addSPField",
                         "fieldType": "User",
                         "displayName": "Contact",
                         "addToDefaultView": true,
                         "isRequired": true
                     },
                     {
                         "verb": "addSPField",
                         "fieldType": "Note",
                         "displayName": "Meeting Notes",
                         "isRequired": false
                     }
                 ]
             }
         ],
             "bindata": { },
     "version": 1
 }
 '@

但是,当我粘贴此内容并按Enter键时,什么也没有发生,并且指针仅指向如下所示的新行>>,下面是屏幕截图: enter image description here

我需要做些什么吗? (对于PowerShell还是新手)

1 个答案:

答案 0 :(得分:2)

您的代码发布错误是最后一行的末尾包含一个空格。

$Test = @'
    Stuff...
 '@ #This is wrong as there is a space before '@

$Test = @'
    Stuff...
'@ #This is correct