Variable Substitution within Single Quotes

Welcome Forums General PowerShell Q&A Variable Substitution within Single Quotes

This topic contains 5 replies, has 4 voices, and was last updated by

 
Participant
2 years, 6 months ago.

  • Author
    Posts
  • #49543

    Participant
    Points: 2
    Rank: Member

    Hi Guys,

    I'm trying to programatically configure WinRM for a number of servers, and am having an issue with one of the commands.

    winrm create winrm/config/listener?Address=*+Transport=HTTPS @{Hostname="$hostname";CertificateThumbprint="$thumbprint"}

    Now – Powershell see's the @ symbol as an operator (array?) and therefore this command only works if i use single quotes before the @ and at the end of the line (and using actual values for hostname and thumbprint, but doing so means that my two variables $hostname and $thumbprint are taken as literals.

    Any ideas on how to approach this?

    Thanks very much.

    Dan

  • #49546

    Participant
    Points: 0
    Rank: Member
    Start-Process -FilePath 'winrm.exe' -ArgumentList "create","winrm/config/listener?Address=*+Transport=HTTPS","@{Hostname='$hostname';CertificateThumbprint='$thumbprint'}" -Wait

    Give that a try.

  • #49548

    Member
    Points: 0
    Rank: Member

    This will probably also work:

    winrm create winrm/config/listener?Address=*+Transport=HTTPS "@{Hostname=`"$hostname`";CertificateThumbprint=`"$thumbprint`"}"
    

    That being said, you can also just create listeners via the WSMan:\ drive in PowerShell, which avoids the need for the quotes / escaping:

    New-Item -Path WSMan:\localhost\Listener -Address * -Transport HTTPS -HostName $hostname -CertificateThumtprint $thumbprint
    
  • #49551

    Participant
    Points: 1
    Rank: Member

    Here some info i found:

    winrm, HTTPS, wildcard certificate

  • #49553

    Participant
    Points: 2
    Rank: Member

    Guys – thank you very much for your help – i'll give the native powershell code a try 😉

    Dan

  • #49567

    Participant
    Points: 2
    Rank: Member

    one thing that I don't seem to be able to do is to execute this command remotely (in my case via VMware PowerCLi Invoke-VMScript) – i get Access Denied. I'm able to generate the self-signed certificate without an issue.

    Is there a limitation on the WSMan:\ namespace that means it can't be manipulated remotely?

    Thanks,

    Dan

The topic ‘Variable Substitution within Single Quotes’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort