Last active
May 8, 2021 14:45
-
-
Save rebrec/2a9867264468d93c93bdf473eb65afa3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################################################## | |
# Description: | |
# This script helps Extensions creators to quickly create a new extension that can add some contextual menu | |
# to their desired location (Collection, Software Update group, whatever the Administrator UI Allows...) | |
# When creating an extension in SCCM, you need to define with which component of the UI it will interact. | |
# this guid is a bit difficult to find (you need to search through XML files). | |
# For this purpose, this script will create an extension action per UI component so that everywhere you | |
# can right click in the SCCM Administrator User Interface, a contextual menu will appear with it's GUID displayed | |
# clicking on this GUID will copy it to the clibpard. | |
################################################################################################################## | |
# Warning: | |
# This script will create extensions in the folder ($$env:SMS_ADMIN_UI_PATH\..\..\XmlStorage\Extensions\Actions) | |
# /!\ Warning 1: TAKE TIME TO BACKUP THE EXTENSION FOLDER ^. | |
# On a default installation, THE FOLDER TO BACKUP IS: | |
# C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\XmlStorage\Extensions | |
# | |
# /!\ Warning 2: Don't run this on production if you are unsure of what you are doing. | |
# On my test machine, running this script will result in the creation of 6000 files which will slow down | |
# Admin UI loading time. | |
# Even if it's not specifically dangerous, it's never good to play on production environments. | |
################################################################################################################## | |
# Usage : | |
# - Run this script once AS ADMINISTRATOR | |
# - Close and start again the SCCM Admin Console | |
# - Right click everywhere in the UI to reveal the associated GUID | |
# - Create your extension's actions with this GUID | |
################################################################################################################## | |
# Credits: | |
# Credits goes to this great article: https://www.ephingadmin.com/create-your-own-right-click-tools/ | |
# Modifications from the original code: | |
# - Modified the way clipboard is set | |
# - Force the script to require Admin right to have appropriate right for folder / file creation | |
################################################################################################################## | |
#Requires -RunAsAdministrator | |
$ConfigInstallPath = $env:SMS_ADMIN_UI_PATH | Out-String | |
$ConfigInstallPath = $ConfigInstallPath.Trim() | |
$XMLPath = $ConfigInstallPath -replace "\\bin\\i386", "\XmlStorage\ConsoleRoot" | |
$ActionsPath = $ConfigInstallPath -replace "\\bin\\i386", "\XmlStorage\Extensions\Actions" | |
Get-ChildItem "$XMLPath" -Filter "*.xml" -Recurse | ForEach-Object { | |
$FullFileName = $_.FullName | |
$FileContent = Get-Content $FullFileName | |
foreach ($line in $FileContent) { | |
if ($line.ToUpper().Contains("NAMESPACEGUID=")) { | |
$SplitLine = $line.Split("`"") | |
$GUID = $SplitLine[1] | |
$FilePath = "$ActionsPath\$GUID" | |
New-Item -ItemType Directory -Path $FilePath -ErrorAction SilentlyContinue | Out-Null | |
$strOutput = "<ActionDescription Class=`"Executable`" DisplayName=`"$GUID`" MnemonicDisplayName=`"$GUID`" Description=`"$GUID`">`n" | |
$strOutput = $strOutput + "<ShowOn><string>ContextMenu</string></ShowOn>`n" | |
$strOutput = $strOutput + "<Executable><FilePath>cmd.exe</FilePath>`n" | |
$strOutput = $strOutput + "<Parameters> /c Powershell.exe -Command ""Set-Clipboard '$GUID'""</Parameters></Executable>`n" | |
$strOutput = $strOutput + "</ActionDescription>" | |
$strOutput > "$FilePath\File.xml" | |
Write-Host "File $FilePath\File.xml created!" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment