A few months ago I released the first public version of my Import Computer Form. I’ve had some nice feedback about it and also some good ideas for added functionality. This update will mainly be about three things:
- Cleaning-up old code, by merging a few lines and adjusting some queries.
- Adding error catching, by introducing an error provider for faulty input.
- Adding functionality, by introducing an option to add a User Device Affinity/ Primary User.
These additions mean that this version gives the user the possibility to perform the following actions, without the need of access to and/ or a locally installed ConfigMgr console:
- Fill in a Computer name.
- Fill in a MAC Address.
- Select an OS Deployment Collection.
- Select a Primary User.
- Import the Computer Information.
- Add the User Device Affinity/ Primary User.
- Close the form.
I thought it might be nice to give some information about how easy it actually is to add this new functionality of adding a User Device Affinity/ Primary User. First start with looking for the class and the methods that hides the functionality that is needed. This can be done by, either browsing through WMI, or searching through the online reference on MSDN. As the screenshot shows, I like to use WMI Explorer. It also show that browsing to the class SMS_UserMachineRelationship reveals the method CreateRelationship, which again reveals its four parameters. For the exact information about the parameters it’s still necessary to look at MSDN. The “fun” part is that the input, of the parameters, is required in the order as shown in WMI. The order shown at the different MSDN articles is NOT the order needed as the input! After all the input is collected, the command line is “just” adding it all together in one Invoke-WmiMetod command, like this:
Invoke-WmiMethod -Namespace root/SMS/site_$($SiteCode) -Class SMS_UserMachineRelationship -Name CreateRelationship -ArgumentList @($ResourceID, 2, 1, $UserName) -ComputerName $SiteServer
Note: I used exactly the same way to change my method, for importing a machine, into a “one-liner”. This made it to an Invoke-WmiMethod for the class SMS_Site and the method ImportMachineEntry, like this:
Invoke-WmiMethod -Namespace root/SMS/site_$($SiteCode) -Class SMS_Site -Name ImportMachineEntry -ArgumentList @($null, $null, $null, $null, $null, $null, $MACAddress, $null, $ResourceName, $True, $null, $null) -ComputerName $SiteServer
As of today this updated version of my Import Computer Form is publicly available via the TechNet Galleries. Please let me know what you think of the tool.