0

a site has a directory structure like this:

https://web.site.net/documents/2018/

where 2018 is the year

my code is like this:

$year = Read-Host -Prompt 'Enter Year'
(Invoke-WebRequest -uri 'https://web.site.net/documents/$year/').Links.href | 
Select-string 'https://web.site.net/documents/$year/#'

How do I properly escape, so that the year properly goes into the url?

1 Answer 1

2

Try using double quotes instead of single quotes. In Powershell, double quotes around a value signify that variable names should be substituted for their contents. On the other hand, single-quoted values are treated as literals.

(Invoke-WebRequest -uri "https://web.site.net/documents/$year/").Links.href | 
Select-string "https://web.site.net/documents/$year/#"

See this page for more information about single versus double quotes in Powershell.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.