Code Snippets

Here are some code snippets for automating small tasks.

Powershell: Listing all of the Computer Objects in the Unassigned OU, the Owner, and Last Updated timestamp:

Powershell: Check to see if hotfix is installed and if not, install appropriate one based on OS.

Powershell: Run a batch file, retaining the working directory, with UAC elevation:

Powershell: Get the local serial number (or service tag if its a Dell):

Powershell: If a GPO has “AllSettingsDisabled” set on it, well, it has all settings disabled. Its inert. Useless. Running the 2 lines of code below yeilds all GPO’s in the domain with that set.

Powershell: The following couple lines of code will use Out-GridView to display every GPO in the whole domain that has 0/zero/zilch links to GPO’s. If something is linked to the root of the domain or a Site, it will show up in the list too, but this gets the point across.

Powershell: Fun with Out-Gridview!

Powershell: Search through SYSVOL for stuff that shouldn’t be there.

Powershell: Locate all of the ancient objects with SID Histories from when ADMT was used.

Powershell: Delete domain profiles from a local machine

Powershell: Function to test spelling

Powershell: Writing to the Event Log