I've encountered a strange issue with powershell. When calling the mkdir command with a powershell var it appears that powershell appends to the variable, although this only occurs if inside a function call.
I have the following sample code.
function TestStuff($test) {
Write-Host "Called with parameter: $test"
$newPath = Join-Path "C:\testy\" $test
mkdir $newPath
# It's ok here
Write-Host "New path is: $newPath"
return $newPath;
}
$myNewPath = TestStuff "testVar"
# It's been doubled up here
Write-Host "Returned from function it is: $myNewPath"
This produces the following output
Called with parameter: testVar
New path is: C:\testy\testVar
Returned from function it is: C:\testy\testVar C:\testy\testVar
Buried within a powershell script this issue was tricky to spot. Is anyone able to explain this behaviour. The eventual solution got re-written so it was not a function call. The other alternative was to pipe the output of mkdir to null as follows: mkdir $myPath > null Although this produces a file named null on file system but didn't seem to fiddle with the $myPath var.