Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Dot sourcing a function with same variable as outside this function

$
0
0

Hello everybody

 

I've got a little understanding problem with the following script:

function do-something {
param($path)
$path
}
$Path = "D:\Temp"
Write-Host $Path
. do-something -path "C:\Temp"
Write-Host $Path

Because of dot sourcing this function (this is a short version, the original script really needs to be dot sourced) into the same script, the variable $path will be overridden by the passed parameter into the function. The result is the following:

D:\Temp
C:\Temp
C:\Temp

Is there a solution to keep the variable outside the function with the value "D:\Temp" without changing the variable name inside the function ?

 

Any help is welcome.

Many thanks and best wishes,
maragam 


Viewing all articles
Browse latest Browse all 6937

Trending Articles