This post is useful, and I landed here from looking for a variable extension inside the current PowerShell row in an SQL query.
The following snapshot will get a list of servers, and then a loop in the Foreach-Object , which allows you to replace the server name for each request!
Thanks to @Matt for the hash table .
$servers = Get-Content c:\scripts\list.txt $servers | ForEach-Object{ $items = @{} $items.Server = $_ $query = @" WHERE svrName = $($items.Server) "@ }
source share