1

I have the following code and would like to return the string value for aaa, depending on what is in the ADProps.physicalDeliveryOfficeName supplied to the GetOfficeLocation function.

The switch seems to do what it should but it won't return the string value, perhaps I am referencing it incorrectly when outputting $a["aaa"]?

$global:newcastle = @{
"Value 1 newcastle" = @{
    "aaa" = "newcastle string";
    }
}

$global:london = @{
"Value 1 london" = @{
    "aaa" = "london string";
    }
}

$global:heathrow = @{
"Value 1 heathrow" = @{
    "aaa" = "heathrow string";
    }
}

$ADProps=@{
    'physicalDeliveryOfficeName'= "heathrow airport";
}

function GetOfficeLocation ($office) {
    switch ( $office )
    {
    "newcastle" {$location = "newcastle"; break}
    "london city" {$location = "london"; break}
    "heathrow airport" {$location = "heathrow"; break}
    }
    return $location
}

$a = GetOfficeLocation($ADProps.physicalDeliveryOfficeName)
$a["aaa"]

Result is that nothing gets output to the console.

Desired result in this example would be for this to be displayed: heathrow string

Effectively I am trying to determine which @global variable to choose and then access its members from then on.

edit

How do I return the value heathrow string, based on passing heathrow airport as a parameter into the GetOfficeLocation function? I would also like to be able to return newcastle string or london string by changing the input accordingly.

4

2 Answers 2

2

You could reach this using hashtable. Like so:

$HashTable = @{
    'newcastle' = 'newcastle';
    'london city' = 'london';
    'heathrow airport' = 'heathrow';
}

$ADProps=@{
    'physicalDeliveryOfficeName'= "heathrow airport";
}

Calling key 'heathrow airport' will return its corresponding value heathrow

$HashTable[$ADProps.physicalDeliveryOfficeName]
heathrow
Sign up to request clarification or add additional context in comments.

Comments

1

i think what you are trying to do is something like this:

heathrow = @{
    aaa = "heathrow string"
}
$a = GetOfficeLocation($ADProps.physicalDeliveryOfficeName)
(Get-Variable -Name $a).value.aaa

but i dont know, code is completely not clear

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.