Beckhoff / ADS

Beckhoff protocol to communicate with TwinCAT devices.
MIT License
515 stars 197 forks source link

Add-AdsRoute PowerShell #167

Closed Caillic closed 1 year ago

Caillic commented 2 years ago

Hello,

I'm working to do a software to create the ADS Route automatically with a software. I'm using VB.net and PowerShell, but no matter. I coded on my software the execution of the creation of the route "Ads-Route" and the validation of the route with "New-TcSession".

***** PS1 FILE COMMAND ** $User = "Administrator" $PWord = ConvertTo-SecureString -String "1" -AsPlainText -Force $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord

Add-AdsRoute -Credential $Credential -name "PLC_Main" -NetId 5.96.152.65.1.1 -IPOrHostName 192.168.12.15 New-TcSession -NetId '5.96.152.65.1.1' -port 851


The command is working with my computer but when i used a blank computer with windows 10. After install TcXaemgmt pakage manually in "C:\Program Files\WindowsPowerShell\Modules\TcXaeMgmt" Power shell return this error :

***** POWERSHELL EXCEPTION ERROR RETURN ** Add-AdsRoute : Parameter set cannot be resolved using the specified named parameters. At E:\PowerShell\ConnectPWSHELL.ps1:6 char:1 Add-AdsRoute -Credential $Credential -name "PLC_Main" -NetId 5.96.152 ...

CategoryInfo : InvalidArgument: (:) [Add-AdsRoute], ParameterBindingException FullyQualifiedErrorId : AmbiguousParameterSet,TwinCAT.Management.Automation.AddRoute


I remind you that it works with my computer. Does somebody have an idea ?

RalfHeitmann commented 2 years ago

Is TwinCAT installed on the 'blank computer'? Another reason could be that a different .NET infrastructure is used (Microsoft Powershell vs. Windows Powershell and different versions of them). That could be another reason. Could you indicate the Powershell versions and the TcXaeMgmt versions you are using (on both computers?)

PS> $psVersionTable

Name                           Value
----                           -----
PSVersion                      7.2.5
PSEdition                      Core
GitCommitId                    7.2.5
OS                             Microsoft Windows 10.0.19043
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

PS> import-module TcXaeMgmt
PS> Get-module TcXaeMgmt
get-module TcXaeMgmt

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     6.0.33                TcXaeMgmt                           {Add-AdsRoute, Add-MqttRoute, Close-TcSessio…
Caillic commented 2 years ago

In reality I have installed on several computers, including two identical new identical computer. On number 1: Powershell command works.

On number 2: I have the error message quoted above.

In both cases, I did the test of the versions as you had advised me the same result :

$PSVersionTable

NameValue


PSVersion 5.1.19041.1682 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.19041.1682 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1

PS U:> import-module TcXaeMgmt

PS U:> Get-module TcXaeMgmt

ModuleType Version Name ExportedCommands


Script 6.0.27 TcXaeMgmt {Add-AdsRoute, Add-MqttRoute, Close-TcSession, Copy-AdsFile...}

PS U:> Get-ExecutionPolicy Unrestricted

Caillic commented 2 years ago

I didn't repond to your first question only Twincat ADS is installed on the customer computer.

RalfHeitmann commented 2 years ago

Thats interesting - I cannot reproduce the problem here. There must be a difference between both computers. The error message

Add-AdsRoute : Parameter set cannot be resolved using the specified named parameters.

indicates me, that there is a problem with parsing the arguments of the line

Add-AdsRoute -Credential $Credential -name "PLC_Main" -NetId 5.96.152.65.1.1 -IPOrHostName 192.168.12.15

This behaviour can only change between computers if the loaded and used Powershell Module is different (with different Add-Route parameter sets) or the Powershell Argument Parser behaves differently. That would lead to a different Powershell version.

A few ideas you could (double) check:

Caillic commented 2 years ago

Hello,

Since the problem appear I use the command only by the powershell terminal, ou the ISE.

Yesterday, I remenber on the PC-1 in install the module TcXaeMgmt 3.2.31 by internet using this command : Install-Module -Name TcXaeMgmt -RequiredVersion 3.2.31 -Force -AllowClobber -Scope CurrentUser

And the Second PC-2, I just copy the TcXaeMgmt in the folder : C:\Program Files\WindowsPowerShell\Modules and i do the import using this command : Import-Module -Name TcXaeMgmt -RequiredVersion 3.2.31 -Force

I restart my computer and the probleme was gone, I thinking oh that working install by web and restart the windows. Restarting windows solve many problem.

But I decided to uninstall the module TcXaeMgmt and to restart the computer and to try again the web installation and a restart but the problem is still here !

I'm very confused

For information when i use manually the ADS service that working but by command powershell that still doesn't work.

I would like to install the version 6.0.33 but that return an error about the PowerShellGetFormalVersion :

PS C:\windows\system32> Install-Module -Name TcXaeMgmt -Force WARNING: The specified module 'TcXaeMgmt' with PowerShellGetFormatVersion '2.0' is not supported by the current version of PowerShellGet. Get the latest version of the PowerShellGet module to install this module, 'TcXaeMgmt'.

RalfHeitmann commented 2 years ago

That problem could be an outdated version of the PowershellGet Version. Windows Powershell 5.1 comes initially with an old version 1.0.0.1 of that package manager. This causes some trouble because it is not using TLS1.2 internally and should be updated to the actual version 2.2.5. At least the error message states that you should update

PS> Install-Module PowershellGet

should be enough.

 get-module PowershellGet -list

    Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     2.2.5      PowerShellGet                       {Find-Command, Find-DSCResource, Find-Module, Find-RoleCap...
Script     1.0.0.1    PowerShellGet                       {Install-Module, Find-Module, Save-Module, Update-Module...}

Does that help for the 'Install-Module' issue?

RalfHeitmann commented 2 years ago

By the way, you should try to reproduce the issue out of the Powershell terminal when using a 64-Bit system, not the Powershell ISE. The ISE is running as 32-bit process what means its using the 32-bit Powershell which could have sometimes different behaviour than the 64-Bit version. If you are using an 32-Bit System there is no difference.

Caillic commented 2 years ago

Yes, that resolve the issue of the PowerShellGetFormatVersion '2.0' But my original problem still here.

RalfHeitmann commented 2 years ago

This issue was discussed/resolved? with the customer. I something still remains please open a ticket on the standard Beckhoff support channel --> Can be closed here, its the wrong place anyway.

Caillic commented 2 years ago

Hello,

The problem is solved, I must install PowerShell 7, copy the module folder manually in the good environement folder and to import it.

Thank you