Skip to content

Instantly share code, notes, and snippets.

View ForceRestartProgram.ps1
$RestartProgram = Get-CimInstance -ClassName "CCM_SoftwareDistribution" -Namespace "ROOT\ccm\policy\machine\actualconfig" | Where-Object {$_.PKG_Name -match "Restart Computer" -and $_.PRG_ProgramName -match "Exit Force Restart"}
$RestartProgramDeployID = $RestartProgram.ADV_AdvertisementID
$RestartProgramPackageID = $RestartProgram.PKG_PackageID
$RestartProgramProgramID = $RestartProgram.PRG_ProgramID
[XML]$XML = $RestartProgram.PRG_Requirements
$Schedule = $xml.SWDReserved.ScheduledMessageID
$Program = ([wmi]"ROOT\ccm\policy\machine\actualconfig:CCM_SoftwareDistribution.ADV_AdvertisementID='$($RestartProgramDeployID)',PKG_PackageID='$($RestartProgramPackageID)',PRG_ProgramID='$($RestartProgramProgramID)'")
$Program.ADV_RepeatRunBehavior = 'RerunAlways'
@gwblok
gwblok / ExportTSCopies.ps1
Created Feb 3, 2020
Export Task Sequence Copies and Content
View ExportTSCopies.ps1
<# @gwblok - GARYTOWN.COM
2020.02.03 - Initial Release
This script takes the TS's you specify and creates copies of it and any task sequences that it calls (Run Task Sequence Step)
It then builds folders structures for it to maintain versioning.
The first run, you might see some errors as it might look for the previous export, and you won't have one yet.
You'll need to update Server Paths for where you will be keeping the logs and the exports.
You'll need to update the SFTP info (at the end) if you plan to upload to SFTP server.
It also exports the Packages you set as well, so you'd need to update that list.
Look over the script, I've got comments along the way that help explain what is going on.
@gwblok
gwblok / GetMachineDatabase-WithPrompts-FromCM.ps1
Last active Apr 16, 2021
Dynamically create Collections based on your Hardware Inventory in CM
View GetMachineDatabase-WithPrompts-FromCM.ps1
<#V2020.01.27
Updated Script to Create "Operational" Folder and then move newly created Collections there.
Borrowed Code from Benoit Lecours
Made script pull addtional info dynamic, you shouldn't have to make any environmental chanages for script to work.
Script now also creates an "All Workstation" Collection and uses that as the limiting collection, unless one with that name already exist, then uses that.
Change the Limiting Collection info by updating: $LimitingCollection
You can easily modify the Collection Prefix now by changing these below:
$ModelColPrefix = "ModelCol"
$ManufacturerColPreFix = "ManufacturerCol"
@gwblok
gwblok / DownloadContentviaBITS.ps1
Created Jan 15, 2020
The idea behind this is for pre-caching. You provide a Package ID, the script reaches out to DP and builds a list of all the files It then makes BITS Transfer calls to each file pulling it down to your destination.
View DownloadContentviaBITS.ps1
<#GARYTOWN.COM - @GWBLOK - Assisted big time by Jeff Scripter.
The idea behind this is for pre-caching.
You provide a Package ID, the script reaches out to DP and builds a list of all the files
It then makes BITS Transfer calls to each file pulling it down to your destination.
Since it's using BITS, it is also then using BranchCache (Assuming you have BranchCache Enabled)
Once Completed, you can then delete the destination (since it's then in branchcache).
If you don't want to actually delete what you download, Comment out the Delete Line at the end.
#>
@gwblok
gwblok / Reset-TS.ps1
Created Jan 13, 2020
Reset-TaskSequence Function - Software Center "Installing" Spinning Wheel Reset
View Reset-TS.ps1
#Reset Task Squence - When Software Center shows "Installing" but nothing is really happening.
function Reset-TaskSequence
{
$OutputText = "Resetting CM Services to clear out TS - Takes about 3 minutes"
CMTraceLog -Message $OutputText -Type 2 -LogFile $LogFile
Set-Service smstsmgr -StartupType manual
Start-Service smstsmgr
start-sleep -Seconds 5
if (Get-CimInstance -Namespace root/ccm -ClassName SMS_MaintenanceTaskRequests )
{
@gwblok
gwblok / Test-CustomActions.ps1
Created Jan 8, 2020
Windows 10 Upgrades - Test Custom Actions Script (Run during TS)
View Test-CustomActions.ps1
<# GARYTOWN.COM / @gwblok
Custom Actions in the Setup Process
This script creates each of the 6 batch files, along with associated powershell files.
It then populates the Batch file to call the PS File
It then populates the PS File with the command to create a time stamp.
Note, assumes several task sequence variables (SMSTS_BUILD & RegistryPath) as the location to write the data to
Goal: Confirm when the Scripts run and compare to other logs
@gwblok
gwblok / Windows10BuildWebData.ps1
Created Dec 26, 2019
Pulls Windows 10 Release Information from Microsoft Website - Scrap HTML
View Windows10BuildWebData.ps1
<#
@gwblok (GARYTOWN.COM) 2019.12.26
Used to Grab Windows 10 Release Info and pull into PowerShell
Pulling Tables in was stolen from: https://www.leeholmes.com/blog/2015/01/05/extracting-tables-from-powershells-invoke-webrequest/
#>
$URL = "https://winreleaseinfoprod.blob.core.windows.net/winreleaseinfoprod/en-US.html"
[Microsoft.PowerShell.Commands.HtmlWebResponseObject]$WinReleaseWeb = Invoke-WebRequest -Uri $URL
@gwblok
gwblok / Get-HPBuildSupport.ps1
Created Dec 23, 2019
Checks if the current installed OS build is supported by HP
View Get-HPBuildSupport.ps1
$CurrentBuild = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name 'ReleaseID'
$SupportedOSList = $null
$SupportedOSList = Get-HPDeviceDetails -oslist | Where-Object {$_.OperatingSystemRelease -eq $CurrentBuild}
if ($SupportedOSList -ne $null){Write-Output "Compliant"}
else{Write-Output "$CurrentBuild not supported by HP"}
@gwblok
gwblok / Get-HPBIOSVerCompliant.ps1
Created Dec 23, 2019
Check if HP BIOS is Current
View Get-HPBIOSVerCompliant.ps1
#Check if HP Bios is Current
[version]$BIOSVersionInstalled = Get-HPBIOSVersion
[version]$BIOSVersionAvailableOnline = (Get-HPBIOSUpdates -latest).Ver
if ($BIOSVersionInstalled -lt $BIOSVersionAvailableOnline)
{Write-Output "Has $($BIOSVersionInstalled), Needs: $($BIOSVersionAvailableOnline)"}
else {Write-Output "Compliant"}
@gwblok
gwblok / HPCMSL_CI_Detection_Methods.ps1
Last active Apr 30, 2020
HPCMSL CI Detection Methods
View HPCMSL_CI_Detection_Methods.ps1
#Detection Method for HP Client Management Script Library
(Get-WmiObject -Namespace 'root\cimv2\sms' -Query "SELECT ProductVersion FROM SMS_InstalledSoftware where ARPDisplayName like 'HP Client Management Script Library'").ProductVersion
#Detection Method for HP BIOS Version Compliance / Detection Method for HP Model Supported on Current OS
$HPCMSLVers = (Get-WmiObject -Namespace 'root\cimv2\sms' -Query "SELECT ProductVersion FROM SMS_InstalledSoftware where ARPDisplayName like 'HP Client Management Script Library'").ProductVersion
if ((Get-CimInstance -Namespace root/cimv2 -ClassName Win32_ComputerSystem).Manufacturer -like "H*"){$IsHP = $true}
if ($HPCMSLVers -ne $Null -and $IsHP -eq $true)
{