Questions

Adding variable for invoke-command??

+
0 Votes
Locked

Adding variable for invoke-command??

jcwfbi
If I run the cmd:
$session = new-pssession -configurationuri http:..servername.fqdn, then add:
invoke-command -session $session -scriptblock{cmd...}

I found that this will run a command on a remote machine as if i am running it locally.

My problem is I want to specify a variable in the -connectionuri.
I have a list of servers in a variable called $severlist. In this list the servers are labeled as server01,server02, etc. I have another variable that contains the domain name itself that the servers are in called $domain. In it i have the name domain.com more than once since there are more than one sever in the domain.

So I'm wanting to do two things, one I want to be able to add the variables $domain, and $serverlist into another variable so that I get something like this:
server01.domain.com. From there add that to the -connectionuri, so that the session can be run on all the servers in the variable. It seems that the http://wants the entire server name, and I don't see a way of getting around that, unless you can use something other than http? End result is to have something like:

new-pssession -configurationname microsoft.exchange -connectionuri $variable. Is this possible??

Any ideas?? Thx.