Sub Expression using Read Host

This topic contains 2 replies, has 2 voices, and was last updated by  Delonte Johnson 1 week, 5 days ago.

  • Author
    Posts
  • #81245

    Delonte Johnson
    Participant

    Can someone please explain to me why this doesn't work?

    Get-Item "'\\$(Read-Host 'Specify Computer')\c$\Program Files (x86)\Microsoft Office\root\Office16\winword.exe'"
    "'\\$(Read-Host 'Specify Computer')\c$\Program Files (x86)\Microsoft Office\root\Office16\winword.exe'" | Get-Item

    Write-Host behaves exactly as I would expect...

    Write-Host "'\\$(Read-Host 'Specify Computer')\c$\Program Files (x86)\Microsoft Office\root\Office16\winword.exe'"
    "'\\$(Read-Host 'Specify Computer')\c$\Program Files (x86)\Microsoft Office\root\Office16\winword.exe'" | Write-Host

    Also, if I manually provide string it works fine.

    Get-Item "'\\computer\c$\Program Files (x86)\Microsoft Office\root\Office16\winword.exe'"
    "'\\computer\c$\Program Files (x86)\Microsoft Office\root\Office16\winword.exe'" | Get-Item

    Any idea as to why Get-Item wants to append the target location to the current location in this circumstance?

    Thanks in Advance

  • #81253

    Don Jones
    Keymaster

    The C$ should probably be C`$ to escape the dollar sign. I'm also not sure what the embedded single quotes are doing for you.

    What's this not doing that you expected it to?

    • #81256

      Delonte Johnson
      Participant

      Removing extra set of quotes resolved issue. I swear initially had a single pair of quotations and it didn't like that because there were spaces in the path so that's why I added the second pair. In any case, it does what I want it to do now so I'm happy 🙂 Thank you sir!

You must be logged in to reply to this topic.