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

PowerShell: SCCM Application Detection Method

PowerShell: Sort IP Address

IPv4

IPv6 sort last

IPv6 soft first

Powershell: Take all of the subfolders from a dfs target and explode them into separate dfs targets. Useful if you are prepping to do file server moves and you want to break up large shares into more manageable pieces.