Create a sample XML extension file to ping a device
Prerequisites :
To follow this part, you’ll need :
- A good text editor with XML highlighting feature if possible.
- The Configuration Manager SDK
First of all, we will have to find a well-hidden information: the GUID of the object we want to attach our menu entry to.
This is one of the “not so clear” information provided in the SDK. Each visible item in the console has a unique ID assigned. Take a look in the console installation folder, you will find a subfolder named “XmlStorage”.
This is where everything resides. The console definition files are located in the “ConsoleRoot” subfolder. Later, we will work in the Extensions subfolder.
Here is the file list of my ConsoleRoot folder:
AssetManagementNode.xml ConnectedConsole.xml IdleConsole.xml IdleNode.xml ManagementClassDescriptions.xml MonitoringNode.xml SiteConfigurationNode.xml SoftwareLibraryNode.xml ToolsNode.xml
Names are almost self-explanatory, so open the file you want and start to scout into it!
Don’t change anything into these files or your console may stop working correctly and you will probably have to re-install it. Working on a copy is advisable.
As you can see, it is not easy to find something in there. So come the second option: internet search! You can easily find some blogs that will list some GUIDs but how reliable these informations are?
My preferred options: use a script to show GUIDs directly in the console. Here is a small PowerShell script that will create a console extension for every single GUID found in a console file.
!! Don’t run this script on a production console !!
Once run you will be able to find easily the required GUIDs but it will highly overload the console!
Here the code of the script:
$consoleXmlList = @("AssetManagementNode","SoftwareLibraryNode") $cfgmgrpath = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\ConfigMgr10\Setup" -Name "UI Installation Directory" $nameSpaces=@() foreach($a in $consoleXmlList){ Select-Xml -Path "$cfgmgrpath\XmlStorage\ConsoleRoot\$a.xml" -XPath "//*[@NamespaceGuid]" | ForEach-Object {$nameSpaces+=$_.Node.NamespaceGuid} } $nameSpaces|Sort-Object |select -Unique | ForEach { $basefilepath = "$($cfgmgrpath)XmlStorage\Extensions\Actions" if(!(Test-Path -Path "$basefilepath\$_")){ New-Item -Path "$basefilepath\$_" -ItemType Directory } $prefix = $_.substring(0,8) Add-Content -Path "$basefilepath\$_\findNS.xml" -Value "<ActionDescription Class=""Executable"" DisplayName=""$prefix"" MnemonicDisplayName=""$prefix"" Description=""$prefix"">" Add-Content -Path "$basefilepath\$_\findNS.xml" -Value "<ShowOn><string>ContextMenu</string><string>DefaultHomeTab</string></ShowOn><Executable><FilePath>c:\Windows\notepad.exe</FilePath></Executable></ActionDescription>" }
Just modify the first line regarding the workplace(s) you want to work on (filename without extension).
Just as an example, running it as-is on my machine created 1038 extension files.
If, later, you want to clean all these files, just search for “findNS.xml” files in all Actions subfolders and delete them. To complete the cleaning run the following command with administrator’s privileges in the Actions subfolder:
for /R %f IN (.) do rmdir "%f"
Now, if you start the console, you will see new entries in every menu you can extend named with the first 6 digits of the corresponding GUID.
In my console, and surely in your console also, there are 2 different GUIDs shown for device contextual menu depending on the context: 3fd01c et ed9dee. A quick look into the “XmlStorage\Extension\Actions\” folder informs us that device contextual menu can be extended by placing an XML file into: – XmlStorage\Extension\Actions\3fd01cd1-9e01-461e-92cd-94866b8d1f39 – XmlStorage\Extension\Actions\ed9dee86-eadd-4ac8-82a1-7234a4646e62
Let’s create the file!
Open a new XML file in your favorite editor and place the following lines in it :
<ActionDescription Class="Executable" DisplayName="open a command prompt" MnemonicDisplayName="open a command prompt" Description="just open a new command prompt"> <ShowOn> <string>ContextMenu</string> <string>DefaultHomeTab</string> </ShowOn> <Executable> <FilePath>C:\Windows\System32\cmd.exe</FilePath> </Executable> </ActionDescription>
Quite simple and self-explanatory. We created a new action (ActionDescription) based on a call of an Executable file (Class=”Executable”). Then we informed the engine that we want it visible in the ribbon as in the context menu (cf: “ShowOn” section ). Finally, we provided exe file location.
For further detailed information, refer to the SDK documentation.
Name this file as you wish and copy it into the folders we found just before (XmlStorage\Extension\Actions\3fd01cd1…….). Now restart the console and check that you have a new menu entry when you right-click on a device.
Opening a command prompt, that’s fine! but let’s make things a little bit more interesting.
Create a new shortcut to the console executable (Microsoft.ConfigurationManagement.exe) and edit its properties to add “/sms:debugview” option to the command line. This will add a new workplace that will help us to discover object information we can forward to our tool.
Start the console and navigate to Overview\devices then right-click on an active device and select “Show Object Details” menu entry. This will bring you to a new workplace. There, select the “Properties” tab to see all available information.
Take a look near the bottom of the list and you’ll see that the name of the device is available.
Note that the property name is “Name”
Then we will modify our XML file as follow:
… <Executable> <FilePath>C:\Windows\System32\cmd.exe</FilePath> <Parameters>/K ping "##SUB:Name##"</Parameters> </Executable> …
We add “/K” to launch the ping command but keep the window open after it ends. Then we request the console to provide the “Name” Property value to our command.
Almost all properties can be passed as parameters, you only need to surround its name with “##SUB:” and “##” as in this example.
Of course, adapt the DisplayName and Mnemonic on the first line to reflect the new behavior, save the file, copy it again in the target folders restart the console and try again.
You’re now able to extend the console with a third party tool or a script of your own!
If you create a script that needs to interact with SCCM infrastructure, 2 specific parameters are available regardless of the object selected: ##SUB:__Server## & ##SUB:__Namespace##.
Be warned that “__SERVER” will contains the server name in its short form (no DNS domain name). This may lead to a non-functional tool if the SCCM server is in a DNS zone that is not resolved by users’ workstation.
Now move to next chapter to create you first extension.