[comment]: # translation:outdated

[comment]: # ({82eb5968-cd91b3fe})
# 获取

[comment]: # ({/82eb5968-cd91b3fe})

[comment]: # ({1b299552-f68e1936})
### 描述

`integer/array script.get(object parameters)`

此方法允许检索符合所给参数的脚本。

[comment]: # ({/1b299552-f68e1936})

[comment]: # ({67ff14a6-aeffdce5})
### 参数

`(object)` 定义所需输出的参数。

此方法支持以下参数。

|Parameter|Type|Description|
|---------|----|-----------|
|groupids|string/array|仅能运行在所给主机组的脚本。|
|hostids|string/array|仅能运行在所给主机的脚本。|
|scriptids|string/array|仅返回所给ID的脚本。|
|usrgrpids|string/array|仅返回所给用户组可以运行的脚本。|
|selectGroups|query|返回可以在`groups`属性中运行脚本的主机组。|
|selectHosts|query|返回可以在`hosts`属性中运行脚本的主机组。|
|sortfield|string/array|根据所给参数对参数进行排序<br><br>可能的值：`scriptid` 和`name`。|
|countOutput|boolean|这些参数对于所有“get”方法都是通用的，在[reference commentary](/manual/api/reference_commentary#common_get_method_parameters) 中有详细描述。|
|editable|boolean|^|
|excludeSearch|boolean|^|
|filter|object|^|
|limit|integer|^|
|output|query|^|
|preservekeys|boolean|^|
|search|object|^|
|searchByAny|boolean|^|
|searchWildcardsEnabled|boolean|^|
|sortorder|string/array|^|
|startSearch|boolean|^|

[comment]: # ({/67ff14a6-aeffdce5})

[comment]: # ({0425a686-7223bab1})
### 返回值

`(integer/array)` Returns either:

-   一个数组对象。
-   检索到对象的数目，如果`countOutput`参数被使用。

[comment]: # ({/0425a686-7223bab1})

[comment]: # ({c38fd778-b41637d2})
### 示例如下

[comment]: # ({/c38fd778-b41637d2})

[comment]: # ({aafd4282-46654cf2})
#### 检索所有脚本

检索所有的已确认的脚本

Request:

``` {.java}
{
    "jsonrpc": "2.0",
    "method": "script.get",
    "params": {
        "output": "extend"
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

Response:

``` {.java}
{
    "jsonrpc": "2.0",
    "result": [    
        {
            "scriptid": "1",
            "name": "Ping",
            "command": "/bin/ping -c 3 {HOST.CONN} 2>&1",
            "host_access": "2",
            "usrgrpid": "0",
            "groupid": "0",
            "description": "",
            "confirmation": "",
            "type": "0",
            "execute_on": "1"
        },
        {
            "scriptid": "2",
            "name": "Traceroute",
            "command": "/usr/bin/traceroute {HOST.CONN} 2>&1",
            "host_access": "2",
            "usrgrpid": "0",
            "groupid": "0",
            "description": "",
            "confirmation": "",
            "type": "0",
            "execute_on": "1"
        },
        {
            "scriptid": "3",
            "name": "Detect operating system",
            "command": "sudo /usr/bin/nmap -O {HOST.CONN} 2>&1",
            "host_access": "2",
            "usrgrpid": "7",
            "groupid": "0",
            "description": "",
            "confirmation": "",
            "type": "0",
            "execute_on": "1"
        }
    ],
    "id": 1
}
```

[comment]: # ({/aafd4282-46654cf2})

[comment]: # ({cc1ef861-b0b740ec})
### 猜你想看

-   [Host](/manual/api/reference/host/object#object_details)
-   [Host group](/manual/api/reference/hostgroup/object#object_details)

[comment]: # ({/cc1ef861-b0b740ec})

[comment]: # ({935a09f2-90dfc753})
### 源

CScript::get() in
*frontends/php/include/classes/api/services/CScript.php*.

[comment]: # ({/935a09f2-90dfc753})
