I am running this script below and when i execute inside of powershell it runs and provides the exact link I am requesting. When I save in a ps1 file and call the file I get this error. Why would it run fine in powershell but not in the actual file?
My code:
$year = $date.year
$date = GET-DATE
$datemonth=$date.month
$month = (Get-Culture).DateTimeFormat.GetMonthName($datemonth)
$url = 'https://health.mil/Reference-Center/Technical-Documents?query=DMIS'
$links=((Invoke-WebRequest –Uri $url).Links | Where-Object {($_.innerHTML -
like "*DMIS ID Monthly*") -and ($_.innerHTML -notlike "*Change*") -and
($_.innerHTML -like "*$month*")}).href
$links
The error:
At C:\Users\Documents\DMIS\web_scrape2.ps1:6 char:178 + ... HTML -notlike "Change") -and ($_.innerHTML -like "$month")}).href + ~~~~~~~~~ The string is missing the terminator: ". At C:\User\Documents\DMIS\web_scrape2.ps1:8 char:1 + Missing closing ')' in expression. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
-like “*DMIS ID Monthly*”)
. Change these to a plain QUOTATION MARK. – lit