Sorry, not following here.
What exactly did you place in the $uplinkkey variable ? The portgroupkey or the portkey ?
If you only give the portgroupkey, how can you then link to a specific uplinkport ?
For example, an uplinkportgroup with 4 ports, named uplink1 to uplink4.
How do you connect a host to let's say port uplink3, while leaving uplink1 and uplink2 free ?