Powershell function being passed too many parameters

Viewed 970

I'm writing a set of PowerShell scripts to monitor the size of various folders. I've run into an error, and I've got no idea what's causing it.

Here is the code, with Write-Host showing what I am expecting and what the variables $ip and $loc actually contain:

function getDriveLetter($ip) {
    Write-Host $ip    # prints:   192.168.10.10 myfolder1\myfolder2\
                      # expected: 192.168.10.10
    switch($ip) {
        "192.168.10.10" {return "E`$"; break}
        "192.168.10.20" {return "D`$"; break}
        default {"Unknown"; break}
    }
}

function getFullPath($loc,$folder) {
    Write-Host $loc    # prints:   192.168.10.10 myfolder1\myfolder2\
                       # expected: 192.168.10.10
    $drive = getDriveLetter("$loc")
    $str = "\\$loc\$drive\DATA\$folder"
    return $str
}

function testPath($loc,$folder) {
    $mypath = getFullPath("$loc","$folder")
    if (Test-Path $mypath) {
        return $true
    } else {
        return $false
    }
}

When I run the command:

testPath("192.168.10.10","myfolder1\myfolder2\")

I'm getting a "False" result, but if I run:

Test-Path "\\192.168.10.10\E`$\DATA\myfolder1\myfolder2\"

The command returns True (as it should).


What have I missed? I've tried forcing the variables to be set with:

$mypath = getFullPath -loc "$loc" -folder "$folder"

but there's no change. If it changes anything, this is on Powershell version 4.

3 Answers
Related