Skip to content

Instantly share code, notes, and snippets.

View Robert-LTH's full-sized avatar
🎯
Focusing

Robert Johnsson Robert-LTH

🎯
Focusing
View GitHub Profile
# Downloads all policies
Invoke-CimMethod -ClassName SMS_Client -Namespace root/ccm -MethodName 'ResetPolicy' -Arguments @{ uFlags = [uint32]0 }
# Clears local policies and downloads all policies again
Invoke-CimMethod -ClassName SMS_Client -Namespace root/ccm -MethodName 'ResetPolicy' -Arguments @{ uFlags = [uint32]1 }
@Robert-LTH
Robert-LTH / UserNotificationState.ps1
Created September 8, 2020 09:26
Runs SHQueryUserNotificationState from shell32.dll and returns the state
$Code = @"
using System;
using System.Runtime.InteropServices;
namespace UserNotificationState {
public class NitsAndBits {
public enum UserNotificationState
{
/// <summary>
/// A screen saver is displayed, the machine is locked,
<#
.SYNOPSIS
Removes a QueryPanePageDescription from the details of an object in the MEMCM Admin Console
.DESCRIPTION
Reads the supplied XML-file and finds the node on which it will remove a PanePageDescription element.
This means that it will remove a tab from the details of an object in MEMCM.
The supplied example removes a tab from applications.
.EXAMPLE
$Params = @{
<#
.SYNOPSIS
Adds a QueryPanePageDescription to the details of an object in the MEMCM Admin Console
.DESCRIPTION
Reads the supplied XML-file and finds the node on which it will add a PanePageDescription element.
This means that it will add a tab to the details of an object in MEMCM.
The supplied example adds a tab which adds a tab to applications which shows a list of devices
which has reported that the application has been installed.
.EXAMPLE
In the file "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\XmlStorage\ConsoleRoot\ManagementClassDescriptions.xml", locate the line where the declaration of SMS_DeploymentType starts (in SCCM 1906 its at line 7771). Should look like:
<ManagementClassDescription Name="SMS_DeploymentType" SuperclassName="SMS_ConfigurationItemBaseClass">
Once you find it look for '<Properties>' and below that line you add:
<ManagementClassPropertyDescription Name="CIVersion" Type="Integer" />
In my file i added it a little bit further down and now my file looks like this:
<ManagementClassPropertyDescription Name="PriorityInLatestApp" Type="Integer" />
<ManagementClassPropertyDescription Name="CIVersion" Type="Integer" />
param(
[string]$BaselineName
)
$ErrorActionPreference = "Stop"
try {
$Params = @{
Namespace = 'ROOT\ccm\Policy\Machine\ActualConfig'
ClassName = 'CCM_DCMCIAssignment'
@Robert-LTH
Robert-LTH / Invoke-SCCMRunScript.ps1
Last active September 3, 2023 15:56
Simple script to use the new sccm feature called "Run Script". The builtin Invoke-CMScript does not accept parameters.
<#
Thank you CodyMathis123 (https://github.com/CodyMathis123) for adding ParameterSets to do it the right way!
Updated 2022-08-22 thanks to Bryan Dam who noticed that the XML definition was changed and Type became DataType.
Also renamed function because SCCM is the old name of the product.
#>
<#
.SYNOPSIS
Run a script with custom parameters over WMI in ConfigMgr
.DESCRIPTION
@Robert-LTH
Robert-LTH / WMI method parameters.ps1
Created May 1, 2019 22:48
The order of WMI method parameters is a pain!
$MethodClass = [WmiClass]"\\COMPUTERNAME\NAMESPACE:CLASS"
$Method = "MethodName"
$InParams = $MethodClass.psbase.GetMethodParameters($Method)
$InParams.PSBase.properties | select Name,Value | format-Table
# Set the parameters with $InParams.Property = ""
# and invoke as follows
$Result = $MethodClass.InvokeMethod($Method, $InParams, $null)
$Result
function Load-Module {
param(
$ModuleName,
[switch]$Force
)
$Params = @{
ErrorAction = 'Stop'
}
if ($Force.IsPresent) {
$Params.Add('Force',$true)
param(
[string]$ExitCode
)
# http://www.msierrors.com/drivers/dpinst-exit-codes-explained/
$DPInstInfo = New-Object psobject @{
PackageInstallationFailure = $false
RebootRequired = $false
<#