Thanks all for the input. The issue turned out to be pretty basic, once I removed the double quotes around $Text and replaced with single quotes all was well! DOH! – user2735454 just now edit
<position> : Missing ')' in method call. - Powershell
-
22-06-2023 - |
Pergunta
I'm trying to re-purpose a function I found online to remove special characters from a string so I can utilize it as an alias within exchange, but I'm getting the above error.
I can't seem to find what this error is complaining about. Here is the function:
Function Convert-ToFriendlyName{
param ($Text)
# Unwanted characters (includes spaces and '-') converted to a regex:
$SpecChars = '!', '"', '£', '$', '%', '&', '^', '*', '(', ')', '@', '=', '+', '¬', '`', '\', '<', '>', '.', '?', '/', ':', ';', '#', '~', "'", '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', ' '
$remspecchars = [string]::join('|', ($SpecChars | % {[regex]::escape($_)}))
# Convert the text given to correct naming format (Uppercase)
$name = (Get-Culture).textinfo.totitlecase(“$Text”.tolower())
# Remove unwanted characters
$name = $name -replace $remspecchars, ""
$name
}
Thoughts? Any insight would be appreciated!
Thanks,
Solução
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow