Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources: Active Threads
Viewing all articles
Browse latest Browse all 8411

Variable within a Variable in a foreach loop

$
0
0

I'm trying to run an invoke-expression command within a foreach loop that uses a variable within a variable.  Is this possible?  Any pointers would be great.

 

Example

$CmdToRun = "Get-Process X -ComputerName $Server

$Servers = "1", "2", "3"

 

foreach ($Server in $Servers) {

              Invoke-Expression $CmdToRun

}


Viewing all articles
Browse latest Browse all 8411

Trending Articles