Attaching references using PowerShell

I'm trying to automate the attachment of references from ProjectWise using PowerShell.

I've found the Edit-PWMicroStationDocuments and trying to see if I can use it. Here is my current code:

$master = Get-PWDocumentsByGUIDs -DocumentGUIDs '83f49a2c-9a0b-47dc-ac2e-ccc92a694b67'

$keyin = "Model Active DesignModel; RF=`"pw://data-pw.bentley.com:dat-pw-01/Documents/D{9b753433-25e4-4feb-a4e9-7df42e9e29af}`",,`"MyLogicalName`",,,,1,;"

$master | Edit-PWMicroStationDocuments -EngineNumber 15 -KeyIn $keyin

But I get the following error:

INFO|Attempting to launch engine and connect to it. This may take some time...
ERROR|Unable to connect to specified engine. Reason: ErrorDifferentRunningEngine

I've tested the keyin and it works fine. I used Get-MicroStationEngines to find the engine number.

Any tips would be helpful!