Skip to content

Tag: Powershell

Changing a computers asset tag in the MDT database

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

Request an overview of installed Microsoft Hotfixes using Powershell

One of my customers requested a overall view of the servers where one or more Microsoft Hotfixes were installed. I’ve used a small and simpel PowerShell script to do that.

This scripts uses a text file (serverlist.txt) to check which servers it needs to use to look for the Hotfix(es). Place each server ona  different line. I have placed the text file on d:\ServerLixt.txt. Use it like this:

server1
server2
server3
..etc

GetHotfix.ps1 generates a overview of installed hotfixes (in this case KB2486635) on the requested servers.

$Servers = Get-Content 'd:\ServerList.txt'
 
Invoke-Command -ComputerName $Servers -ScriptBlock {
    $Result = Get-Hotfix | where {$_.hotfixid -eq 'KB2486635'}
    if ($Result) {
        New-Object PSObject -Property @{Host = hostname; Value = $true}
    } else {
        New-Object PSObject -Property @{Host = hostname; Value = $false}
    }
}

Looking up multiple hotfixes is possibile to extend the script with multiple ‘KB12345678’. For more information about the Get-Hotfix command: slook here.

Leave a Comment