how should I provide to powershell function Uri string with & character, like Get-ValidUri -Uri https://www.youtube.com/watch?v=LZ382nYZPPg&t=421s it always returns error where 'The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double quotation marks ("&") to pass it as part of a string.' I can provide it with double quotes like Get-ValidUri -Uri "https://www.youtube.com/watch?v=LZ382nYZPPg&t=421s" then it works... Thanks in advance !
function Get-WebLinkValid { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [ValidateScript({ ({ "{0}" } -f $TestUri).Trim() })] [ValidateNotNullOrEmpty()] [System.UriFormat]$TestUri )
[System.Uri]$Uri = ({ "{0}" } -f $TestUri).Trim()
script
}