I'm trying to create a script that uses an URL as parameter. Those URLs often have ampersands &. When trying to give an URL with an ampersand I get the following error:
.\test.ps1 -link http://testurl&qdfq
The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double quot
ation marks ("&") to pass it as part of a string.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : AmpersandNotAllowed
I understand that I can workaround this with using double quotes in the string for example:
.\test.ps1 -link "http://testurl&qdfq"
But I don't understand that the $link parameter needs this, as it is defined as as a string:
param (
[Parameter(Mandatory=$true)]
[string]$link
)
Write-information $link -informationaction Continue
Is there another parameter I need to use in stead of [string] to make the command works without double quotes? So I can use:
.\test.ps1 -link http://testurl&qdfq