【问题标题】:Can't add element in array with powershell function无法使用 powershell 函数在数组中添加元素
【发布时间】:2013-06-06 08:56:58
【问题描述】:

我有一个奇怪的问题,我有一个非常简单的功能。

这是我的 powershell 代码

$exclude = @()

function GetOracleDb {
param([string]$servername)
$exclude += $servername
}

GetOracleDb "Myserver2"

$exclude

为什么我的 $exclude 数组是空的?

感谢您的帮助

【问题讨论】:

    标签: function powershell scripting powershell-2.0 powershell-3.0


    【解决方案1】:

    改成这样:

    $global:exclude += $servername
    

    $exclude 在函数内部的作用域与外部的不同。

    【讨论】:

    • 合法的 PowerShell 2.0 也是如此。
    猜你喜欢
    • 2013-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多