Powershell Variable help

Soldato
Joined
18 Nov 2011
Posts
2,561
Location
Caddington
Wonder if you guys can assist with something.

I am writing a script to download 6 files from 3 different FTP locations which can easily be done by doing 3 different downloads but this increases the code (Negligible I know but I prefer doing things in more concise ways)

Now I am trying to get it to build the powershell for me using a foreach loop.

So the basics I have are as follows

FYI LogOutPut Is a function we have that prints whatever we put in "" and catches any red errors etc

PHP:
$DLRegion = @("US","PT","UK")
$PTFiles =@("File1","File2")
$USFiles =@("File3","File4")
$UKFIles =@("File5","Files6")

FOREACH($R in $DLREGION)
    {
    If ($exitcode -eq 0)
        { 
        Start-Sleep 1
        LogOutput "Start $R FTP process"
        }
    }


This obviously prints each of the regions as expected. Now the next thing I wanted to do was to build the UK\US\PT file variable name using the $R variable I.E

PHP:
FOREACH($R in $DLREGION)
    {
    If ($exitcode -eq 0)
        { 
        Start-Sleep 1
        LogOutput "Start $R FTP process"
        FOREACH($F in "$R`Files")
        {
        LogOutPut $F
        }
        }
    }

But this does not work. It prints the variable correctly but not the contents of this variable. There has to be a way to do this but as it is Friday and it has been a long week I cannot get my head around it.
 
Soldato
OP
Joined
18 Nov 2011
Posts
2,561
Location
Caddington
Knew this would happen....sorted it with a hastable.

PHP:
$Rfiles = @{"US" = $USfiles;"UK" = $UKfiles;"PT"=$PTFiles}



$DLRegion = @("US","PT","UK")
$PTFiles =@("File1","File2")
$USFiles =@("File3","File4")
$UKFIles =@("File5","File6")

FOREACH($R in $DLREGION)
    {
    If ($exitcode -eq 0)
        { 
        Start-Sleep 1
        LogOutput "Start $R FTP process"
        $Files = $rfiles.Get_Item("$R")
        FOREACH($F in $files)
        {
        LogOutPut $F
        }
        }
    }
 
Back
Top Bottom