June 2016

Uninstall Microsoft Software Update deployed with SCCM

I recently had to uninstall a Software Update deployed by SCCM 2012 on a Windows 10 client. Before when running SCCM 2007 i used to run WUSA with the following syntax:

wusa.exe / uninstall / kb: <KBnumber> /quiet /norestart

This didnt work  with the /quiet parameter so instead i had to use DISM as i need to be able to uninstall it silently.

DISM takes the packageName of the Software Update as input which can be found by running the following command on a client which have the Software Update installed:

dism /online /get-packages /format:table

Deployment Image Servicing and Management tool
Version: 10.0.10586.0

Image Version: 10.0.10586.0

Packages listing:


--------------------------------------------------------------------------------------------------------- | --------------- | --------------- | ----------------
Package Identity                                                                                          | State           | Release Type    | Install Time    
--------------------------------------------------------------------------------------------------------- | --------------- | --------------- | ----------------
Microsoft-Windows-Client-LanguagePack-Package~31bf3856ad364e35~amd64~da-DK~10.0.10586.0                   | Installed       | Language Pack   | 13-02-2016 16:58
Microsoft-Windows-DiagTrack-Internal-Package~31bf3856ad364e35~amd64~~10.0.10586.0                         | Installed       | Feature Pack    | 30-10-2015 07:26
Microsoft-Windows-Foundation-Package~31bf3856ad364e35~amd64~~10.0.10586.0                                 | Installed       | Foundation      | 30-10-2015 07:26
Microsoft-Windows-InsiderHub-Package~31bf3856ad364e35~amd64~~10.0.10586.0                                 | Installed       | OnDemand Pack   | 13-02-2016 17:02
Microsoft-Windows-LanguageFeatures-Basic-da-dk-Package~31bf3856ad364e35~amd64~~10.0.10586.0               | Installed       | OnDemand Pack   | 13-02-2016 17:02
Microsoft-Windows-LanguageFeatures-Basic-en-us-Package~31bf3856ad364e35~amd64~~10.0.10586.0               | Installed       | OnDemand Pack   | 13-02-2016 17:02
Microsoft-Windows-LanguageFeatures-Handwriting-da-dk-Package~31bf3856ad364e35~amd64~~10.0.10586.0         | Installed       | OnDemand Pack   | 13-02-2016 17:02
Microsoft-Windows-LanguageFeatures-OCR-da-dk-Package~31bf3856ad364e35~amd64~~10.0.10586.0                 | Installed       | OnDemand Pack   | 13-02-2016 17:02
Microsoft-Windows-LanguageFeatures-OCR-en-us-Package~31bf3856ad364e35~amd64~~10.0.10586.0                 | Installed       | OnDemand Pack   | 13-02-2016 17:02
Microsoft-Windows-NetFx3-OnDemand-Package~31bf3856ad364e35~amd64~~10.0.10586.0                            | Installed       | OnDemand Pack   | 11-04-2016 14:54
Microsoft-Windows-Prerelease-Client-Package~31bf3856ad364e35~amd64~da-DK~10.0.10586.0                     | Installed       | Language Pack   | 13-02-2016 16:58
Microsoft-Windows-Prerelease-Client-Package~31bf3856ad364e35~amd64~~10.0.10586.0                          | Installed       | Feature Pack    | 30-10-2015 07:26
Microsoft-Windows-Security-SPP-Component-SKU-Enterprise-GVLK-Package~31bf3856ad364e35~amd64~~10.0.10586.0 | Installed       | Feature Pack    | 13-02-2016 17:20
Package_for_KB3135173~31bf3856ad364e35~amd64~~10.0.1.2                                                    | Installed       | Security Update | 13-02-2016 17:13
Package_for_KB3136561~31bf3856ad364e35~amd64~~10.0.1.0                                                    | Installed       | Update          | 13-02-2016 17:13
Package_for_KB3140741~31bf3856ad364e35~amd64~~10.0.1.0                                                    | Installed       | Update          | 11-04-2016 14:35
Package_for_KB3144756~31bf3856ad364e35~amd64~~10.0.1.0                                                    | Installed       | Security Update | 11-04-2016 14:35
Package_for_KB3149135~31bf3856ad364e35~amd64~~10.0.1.1                                                    | Installed       | Update          | 24-06-2016 15:03
Package_for_KB3154132~31bf3856ad364e35~amd64~~10.0.1.0                                                    | Installed       | Security Update | 24-06-2016 10:01
Package_for_KB3157993~31bf3856ad364e35~amd64~~10.0.1.0                                                    | Installed       | Security Update | 24-06-2016 09:49
Package_for_RollupFix~31bf3856ad364e35~amd64~~10586.218.1.4                                               | Superseded      | Security Update |                 
Package_for_RollupFix~31bf3856ad364e35~amd64~~10586.318.1.7                                               | Install Pending | Security Update | 28-06-2016 12:39

The operation completed successfully.

From the list find the Package Identity Name of the Software Update.

Run this command to uninstall the KB3144756 silently:

DISM.exe /Online /Remove-Package /PackageName:Package_for_KB3144756~31bf3856ad364e35~amd64~~10.0.1.0 /quiet /norestart

It might require a reboot for the update to be fully removed.

Run Hardware or Software Inventory

This function can be used to trigger a Hardware or Software inventory.

To trigger Hardware inventory call the function using:

RunInventory(“Hardware”)

To trigger Software inventory call the function using:

RunInventory(“Software”)

Sub RunInventory(StrType)

	If StrType = "Hardware" Then
		StrType = "Hardware Inventory Collection Cycle"
	ElseIf StrType = "Software" Then
		StrType = "Software Inventory Collection Cycle"
	Else
		Exit Sub
	End If

    ' Create the CPAppletMgr instance.
    Dim controlPanelAppletManager
    Set controlPanelAppletManager = CreateObject("CPApplet.CPAppletMgr")

    ' Get the available ClientActions object.
    Dim clientActions
    Set clientActions = controlPanelAppletManager.GetClientActions()

    ' Loop through the available client actions. Run the matching client action when it is found.
    Dim clientAction
    For Each clientAction In clientActions
        If clientAction.Name =  StrType  Then
            clientAction.PerformAction  
        End If
    Next
    

End Sub

Uninstall MSI if Installed for the Current User

This function takes an MSI product code as input and uninstalls the software if its installed for the current user (ProductState =5)

Sub UnInstPkg (StrProdCode)

Dim oWSHShell : Set oWSHShell = CreateObject("WScript.Shell")
Dim oMSI : Set oMSI = CreateObject("WindowsInstaller.Installer")
Dim UnInstVal : UnInstVal = 1

 Do While UnInstVal &lt;&gt; 0
  If oMSI.ProductState (StrProdCode) = 5 Then
   ReturnVal = oWSHShell.Run("MSIExec.exe /X " &amp; StrProdCode &amp; " /QB!-", 0, True)
   if Not (ReturnVal = 0 OR ReturnVal = 3010) then WScript.Quit ReturnVal
   UnInstPkg (StrProdCode)
  Else
   UnInstVal = 0
  End If

  Loop
End Sub

Prompt to set OSDComputerName

I use this script to set the computer name on virtual computers during task sequence.

The computer naming script in the task sequence is using the serial number which for virtual computers is too long and will cause the task sequence to fail. Therefore its needed to somehow change the computer name. I have placed this script on a network share which i map after the computer have been given the long and faulty serial-number name. The script will prompt for a new computer name which will then overwrite the OSDComputerName task sequence variable.

Set env = CreateObject("Microsoft.SMS.TSEnvironment")
 Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
 Set objWMIService = SWBemlocator.ConnectServer(strComputer,"root\CIMV2",UserName,Password)
 Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS",,48)
 For Each objItem in colItems
   env("OSDComputerName") = InputBox("Please enter a Computer Name:", "Computer Name")
 Next

Find all files with specific content

This Script will search c:\temp to find all files called test.txt that contains the string “server2”.

Get-ChildItem -Path c:\temp -File -Recurse -include test.txt | Select-String -pattern "server2" | Group path | Select Name

 

Replace Text in a File

This script will replace the occurence of “server1” with “server2” in all files called config.ini placed under c:\temp

Get-ChildItem -Path c:\temp -File -Recurse -include config.ini | %{(Get-Content $_) -replace "server1","server2" | Set-Content $_.fullname}