Skip to content

Instantly share code, notes, and snippets.

@keithga
keithga / New-VMWithAssetTag.ps1
Created August 30, 2023 03:58
Create VM with Custom AssetTag
function new-MyVM {
[cmdletbinding()]
param(
[Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
$name,
[Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true,Position=1)]
$AssetTag,
$Switch = ( Get-VMSwitch -SwitchType External | Select-object -first 1 -ExpandProperty Name ),
$DVDPath = 'C:\iso\ipxe\IPXE.NET.23.03.07.iso'
# This script will remove the VM *AND* Vhd
$VMs = get-vm | Out-GridView -OutputMode Multiple
$Disks = $VMs | Get-VMHardDiskDrive | % path
$VMs | stop-vm -Force -TurnOff -Confirm:$False -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
$VMs | Remove-VM -Force -Confirm:$False
@keithga
keithga / Update-Windows7Images.ps1
Created March 14, 2019 02:49
Windows 7 Image Factory
#Requires -RunAsAdministrator
<#
.Synopsis
Auto create a VM from your MDT Deployment Media
.DESCRIPTION
Given an MDT Litetouch Deployment Share, this script will enumerate
through all "Offline Media" shares, allow you to select one or more,
and then auto-update and auto-create the Virtual Machine.
@keithga
keithga / Trace-NetworkwithNetSh.ps1
Created February 23, 2019 02:16
network trace program
#Requires -RunAsAdministrator
<#
.Synopsis
Launch network trace
.DESCRIPTION
Launches network trace and displays a
.EXAMPLE
Example of how to use this cmdlet
.NOTES
@keithga
keithga / find-StringInWULog.ps1
Last active April 4, 2018 16:53
BLOG: example of how to work arround Get-WindowsUpdateLog console issues in a SCCM Configuration Item
<#
.SYNOPSIS
Search WindowsUpdate Logs
.DESCRIPTION
Searches the Windows Update Log for a string
.NOTES
Ready to be used within a
Copyright Keith Garner, All rights reserved.
@keithga
keithga / DeviceCollPerformance2
Created January 26, 2018 05:59
Replacement script for Add-CMDeviceCollectionDirectMembership
<#
Example of how to create a Device Collection and populate it with computer objects
The Faster way. <Yea!>
#>
[cmdletbinding()]
param(
$CollBaseName = 'MyTestCol_0C_{0:D4}',
@keithga
keithga / DeviceCollPerformance1
Created January 26, 2018 05:02
Add-CMDeviceCollectionDirectMembership Slow
<#
Example of how to create a Device Collection and populate it with computer objects
The Slow way. <Yuck>
#>
[cmdletbinding()]
param(
$CollBaseName = 'MyTestCol_03_{0:D4}',
@keithga
keithga / find-DiskHog.ps1
Last active July 10, 2022 03:46
Disk Hog Script
<#
.SYNOPSIS
Report on Disk Hogs
.DESCRIPTION
Returns a list of the largest directories in use on the local machine
.NOTES
Copyright Keith Garner, All rights reserved.
Really Updated for Windows 7 and Optimized for !!!SPEED!!!
.PARAMETER Path
Start of the search, usually c:\
@keithga
keithga / Unattend.xml
Created December 12, 2017 05:37
Silence is Golden
<!-- https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/settings-for-automating-oobe -->
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="specialize">
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ComputerName>*</ComputerName>
</component>
<component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RunSynchronous>
<RunSynchronousCommand wcm:action="add">
@keithga
keithga / MYIT_OEMBypass.ps1
Last active September 22, 2022 17:09
IT OEM Bypass script
<#
Bypass file for OEM OOBE Setup.
Called from within Audit Mode.
#>
param(
[int] $TargetDisk = 0,
[string] $NewBootWim = "$PSScriptRoot\Generic_x64.wim",
[string] $UserName = 'MDTServer\MDTNonInteractive',
[string] $Password = 'UnSecurePassword1234',