My brother (Stefan van Bruggen) wrote this function for me. I will be using this function in my script(s) that I’m writing to allows my customers and co-workers to add and change various information without manually manipulating the MDT SQL database.
The script uses the MDTDB module created by Michael Niehaus (which can be foundĀ HERE). This module allows you to change a lot of information in the database except for the asset tag.
Add this to the MDTDB.psm1 to be able to change the asset tags and the other scripts, which I will post on here soon.
function Set-MDTComputerAssetTag { [CmdletBinding()] PARAM ( [Parameter(ValueFromPipelineByPropertyName=$true, Mandatory=$true)] $id, [Parameter(ValueFromPipelineByPropertyName=$true)] $assetTag ) Process { # Tell SQL which table to edit and what to look for $sql = "UPDATE ComputerIdentity SET AssetTag = '$assetTag' WHERE ID = '$id'" Write-Verbose "About to execute command: $sql" $identityCmd = New-Object System.Data.SqlClient.SqlCommand($sql, $mdtSQLConnection) $identity = $identityCmd.ExecuteScalar() Write-Verbose "Added computer identity record" # Write the updated record back to the pipeline Get-MDTComputer -ID $id } }
Leave a Comment