Changing Serial ports from COMX to COMY using WMI

Scenario: I have a thermal printer connected to a serial port currently assigned the number of COM1, I need to change this port number to say COM55. Now this has to be done silently (ie in code or script), if i had the luxury of just going through device manager i would but that isn't possible as this has to be part of an installer. The terminal services command "Change Port COM1=COM55" relies on group policy settings being correct and is reset when the computer shuts down. And so my only real option without trawling the registry and changing each corresponding key - some of which are dependent on the driver manufacturer - is to use WMI.



#change the qualifiers for "DeviceID" to supposedly allow you to write to it

$writeableProperties = Get-WmiObject -List -Recurse Win32_SerialPort |
    select -Expand Properties | Where-Object { $_.Name -eq 'DeviceID' }

$writeableProperties.Qualifiers.Add("write",$true)

#Pull out the SerialPort
$SP = Get-WMIobject Win32_SerialPort | Where-Object { $_.DeviceID -eq 'COM1' }

#change the Device ID
$SP.DeviceID = "COM55"


This doesn't work as intended, ie it changes the deviceid but that doesn't propagate further, i'm therefore under the impression that there is a parent object to this that determines the port number. I'm fully aware of how bad this all is, but i have little choice.


any help would be greatly appreciated.



K