I am trying to configure WinRM from a PowerShell script. I am using the following code
$WinrmCreate= "winrm create winrm/config/Listener?Address=*+Transport=HTTPS @{Hostname=""$sHostName"";CertificateThumbprint=""$CertificateThumbPrint""}"
Invoke-Expression $WinrmCreate
The hostname and certificate thumprint are variables above and they are validated to be coming out. Verbose output shows
VERBOSE: winrm create winrm/config/Listener?Address=*+Transport=HTTPS @{Hostname="RSNODE1";CertificateThumbprint="6C79C8E6E88779037593E6234DCE6E1A55662F87"}
However, the execution of the "Invoke-Expression" give the following error
Invalid use of command line. Type "winrm -?
Interestingly if I copy/paste the output of my line to a command prompt it will create the listener without error.
Researching execution of commands I find nothing that would explain this behavior. My only theory is that the "winrm" command is a script itself and something is misbehaving.
@cscript //nologo "%~dpn0.vbs" %*