Time sync during OS Deployment

After Microsoft Surface arrived in our production environment we have been challenged by time sync issues during OS deployment. The Surface devices were so much off in date and time that they were rejected by the management point resulting in a failed Task Sequence.

Instead of powering up the Surface and adjusting the time manually i wanted to automate this during deployment. I found out that Niall Brady have made a timesync script that can sync the time on the client with a server using NET TIME.

Adding this script to the prestart command on the Boot image will then sync the time with the server specified prior to running the task sequence and voila – problem solved.

 

Extract Drivers

This script will extract all drivers from a computer and copy them to a folder structure organized by type. It is language dependent and currently works for Danish and English Operating System language.

 

Create OU Based Collections

I recently set up a whole new SCCM 2012 environment and we needed to create collections for a lot of OUs containing the computers.The script below will run through an OU structure and create device collections for each OU and sub OU’s.

To run the script open your SCCM console and press the drop down menu next to the home button and choose “Connect via Windows Powershell”.

This will establish a connection to the SCCM and allow you to use some special CM powershell functions which is utilized in this script.

To avoid warnings about the script not  being digitally signed run this command prior to executing the script it self.

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

Now you can run the script.

It takes 1 mandatory argument and 3 optional which if not specified will default to the values they have in the script.

The mandatory argument is the SearchBase which is the top level OU from which you want to create the OU based Collections. The Optional arguments are LimitingCollection, SearchScope and RefreshType.

To run the script in its most simple form:

New-OUDeviceCollection.ps1 -SearchBase “OU=Computers,OU=Company,DC=OMG,DC=local”

This will create a collection for each of the OU’s under omg.local\Company\Computers – excluding the Computers container it self.

New-OUDeviceCollection.ps1 -SearchBase “OU=Computers,OU=Company,DC=OMG,DC=local” -LimitingCollection “All Windows 10 Computers” -SearchScope Subtree -RefreshType 2

This will create a collection for each of the OU’s under omg.local\Company\Computers – including the Computers container it self. It will use “All Windows 10 Computers” as the limiting Collection and it will use periodic update.

 

Rebuild a corrupt WMI repository

If i run into client computers that have issues with WMI i usually run through these steps:

Run this command to verify WMI:

If the above command returns “inconsistent” then i would run the following command:

Then i would use verifyrepository again to check the state. If it is still “inconsistent” then i would run the following command:

This will stop the WMI service and rename the repository (C:\Windows\System32\wbem\repository) and start the WMI service.

This should resolve the WMI issues.

In case you are in a SCCM environment the affected computer would need its SCCM client reinstalled.

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

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”)

 

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)

 

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.

Find all files with specific content

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

 

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