Adeel ASIF
Adeel ASIF

Reputation: 3524

Can't add element in array with powershell function

I have a strange problem, i have a very simple function.

This is my powershell code

$exclude = @()

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

GetOracleDb "Myserver2"

$exclude

Why my $exclude array is empty?

Thanks for your help

Upvotes: 2

Views: 2143

Answers (1)

CB.
CB.

Reputation: 60918

change it like this:

$global:exclude += $servername

The scope of $exclude inside a function is different from this one outside.

Upvotes: 6

Related Questions