Beckhoff将PowerShell模块作为TwinCAT安装的一部分。完整的文档可在此文件中找到-
Twincat ADS Module
# Import the TwinCAT ADS module
$originalpaths = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PSModulePath).PSModulePath
$newPath = $originalpaths + ';C:\TwinCAT\AdsApi\Powershell'
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PSModulePath -Value $newPath
$env:PSModulePath = [System.Environment]::GetEnvironmentVariable("PSModulePath", "Machine")
# Check if the module was imported
if (-not (Get-Module TcXaeMgmt -listavailable)) { Throw 'The Twincat ADS module was not found!' }
然后必须生成一个要复制的文件列表。
$variant = 'Put your variant here'
$source = '$PSScriptRoot + "\$variant"'
$plcFiles = Get-ChildItem -Path $source -Recurse -Force -File
设置目标路径。
# Windows 10
$destination = '\TwinCAT\3.1\Boot'
# Windows CE
$destination = '\Hard Disk\TwinCAT\3.1\Boot'
遍历列表并复制每个文件。
# Upload the files
foreach ($file in $plcFiles) {
Copy-AdsFile -Path $file.FullName -SessionId $session.Id -Destination $file.FullName.Replace($source, $destination) -Force -Upload
}