Search code examples
powershellpowershell-remoting

When to use -ComputerName and when -ConnectionUri?


In my quest of learning PowerShell I stumbled across something that confuse me. I don't really understand why sometime I have to use

New-PSSession -ComputerName "servername" 

and sometime instead

New-PSSession -ConnectionUri "http://FQDN/powershell" etc...

I couldn't find a clear explanation of the two approaches. What is exactly the difference?


Solution

  • New-PSSession is working over PSremoting, which should be configured before use. Configuration means that you can do it slightly differently for each of the computers. The simplest examples are different ports an different endpoint names. Uri format is as follows: <Transport>://<ComputerName>:<Port>/<ApplicationName>

    For default configuration you need to pass only ComputerName and default values will be taken for all the other values.

    If, however, you have non default configuration, you have a choice:

    • Pass ConnectionURI with all the data
    • UseComputerName, together with UseSSL, Port, and ApplicationNameparameters to specify the ConnectionURI values.

    So it's just 2 ways of passing the same information to command.

    In your example you could do:

    New-PSSession -ConnectionUri "http://FQDN/powershell"
    

    or

    New-PSSession -ComputerName "FQDN" -UseSSl $false -ApplicationName "powershell"
    

    Both will behave exactly the same