Error running power shell "... is not recognized as the name of a cmdlet"

john john 681 Reputation points

I have the following inside my Power Shell PS1 file, to set Tls12 + call .exe :-

Show-Message -Message "Step 1a: Create groups and adding users to it"   
& "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $HelperPath\UpdateView.exe" "true" $Username $Password  

If ((Get-Content $ErrorLogFile) -ne $Null) {  
    Show-Message -Message "Creating group and adding users to it failed" -Type ([MessageType]::Failure)  
    RevertAll $ScriptDirectory 1  

but i am getting this error:-

& : The term '[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;
\UpdateView.exe' is not
recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if
a path was included, verify that the path is correct and try again.
At C:\c\tree\master\cloud\src\deployments\Scripts\Deploy.ps1:352 char:7

  • & "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityPro ...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : ObjectNotFound: ([Net.ServicePoi....UpdateView.exe:String) [], CommandNotFoundException
  • FullyQualifiedErrorId : CommandNotFoundException

any advice please?

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
4,622 questions
No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 35,036 Reputation points

    I see the unknown command in the error message is \UpdateView.exe. Note that there's a "\" in the name, but there's nothing before it. Check the value of the $HelperPath because I don't see that variable being initialized in the code you posted.

    No comments

  2. MotoX80 23,491 Reputation points

    Change the second line to these 2 lines.

    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12  
    & "$HelperPath\UpdateView.exe" "true" $Username $Password  
    No comments