Dynamical get a cached variable?

Good day!

Here is the way I have managed to reference a dynamic name within a loop.

To create the data—

foreach ($Server in $Masterlist){
      Set-Item -PSPath "Cache:$($server.name)background" -Value $cache:BGfail
}

Then to recall the data –

foreach ($Server in $servers) {

 if (($(Get-Item -pspath cache:$($server.name)background) -eq $Cache:BGpass) ) {
      #Do something
 }
 else {
     $Cache:STATICNAME= $Cache:BGfail
 }

}

Also see post Auto-generated Variable names in $Cache: Scope - #2 by OpsEng

1 Like