Join the Stack Overflow Community
Stack Overflow is a community of 6.8 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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

share|improve this question
up vote 3 down vote accepted

change it like this:

$global:exclude += $servername

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

share|improve this answer
    
Legit for PowerShell 2.0 as well. – Signal15 Oct 13 '14 at 22:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.