SCCM Console Extensions – Find the GUID

I wrote some about this topic in a post a while ago… did some more scripting around this today.

This VBScript will read the AdminConsole.xml and look for NameSpaceGuid’s, when it find one it will create a subdirectory (from where it is started) with the GUID and after that it will create a XML-file within that directory.
The XML-file then points to an VBS-file with a couple of parameters. (Look further down for an example of a nice VBScript to use)

Tip: Backup AdminUI\XmlStorage\Extensions\Actions before you start to play around with this.

Const cVbsFile = "testExtension.vbs" ' The file to call on right-click
Const cHKEY_LOCAL_MACHINE = &H80000002
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
oReg.GetStringValue cHKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\ConfigMgr\Setup", "UI Installation Directory", sSccmPath
Set oReg = Nothing

sSourcePath = Replace(WScript.ScriptFullName, WScript.ScriptName, "")

Set oShell = CreateObject("WScript.Shell")
Set oFso = CreateObject("Scripting.FileSystemObject")
Set oFile = oFso.OpenTextFile(sSccmPath & "\XmlStorage\ConsoleRoot\AdminConsole.xml", 1)
Do While oFile.AtEndOfStream <> True
    sText = Trim(uCase(oFile.ReadLine))
    If InStr(sText, "NAMESPACEGUID=") Then
		
		' Read the GUID from NameSpaceGuid param
		sGuid = sText
		sGuid = Right(sGuid, Len(sGuid) - InStr(sGuid, "NAMESPACEGUID=") - 14)
		sGuid = Left(sGuid, InStr(sGuid, """")-1)

		if not oFso.FolderExists(sSourcePath & sGuid) Then
			WScript.Echo sSourcePath & sGuid

			' Create the GUID folder
			oFso.CreateFolder sSourcePath & sGuid

			' Create the XML-file with current Guid, Name & ResourceID as parameter to source-VBScript
			Set oXmlFile = oFso.CreateTextFile(oShell.ExpandEnvironmentStrings("%TEMP%\snowland-guid-locator.xml"), True)
			oXmlFile.WriteLine "<ActionDescription Class=""Executable"" DisplayName=""GUID - " & sGuid & """ MnemonicDisplayName=""GUID locator"" Description=""snowland.se GUID locator"">"
			oXmlFile.WriteLine "<Executable>"
			oXmlFile.WriteLine "<FilePath>" & sSourcePath & cVbsFile & "</FilePath>"
			oXmlFile.WriteLine "<Parameters>" & sGuid & " ##Sub:Name## ##Sub:ResourceID## ##SUB:ItemName## ##SUB:NetworkOSPath## ##SUB:value##</Parameters>"
			oXmlFile.WriteLine "</Executable>"
			oXmlFile.WriteLine "</ActionDescription>"
			oXmlFile.Close

			' Copy XML to GUID-directory with name "snowland-GUID.xml" as name
			oFso.CopyFile oShell.ExpandEnvironmentStrings("%TEMP%\snowland-guid-locator.xml"), sSourcePath & sGuid & "\snowland-" & sGuid & ".xml"
		End if
	End If
Loop
oFile.Close

So… when you restarted the console you will se GUID’s showing up. To get those GUID’s to the clipboard use a testExtension.vbs like this

Set oFso = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")

' Create a temporary file
Set oFile = oFso.CreateTextFile(oShell.ExpandEnvironmentStrings("%TEMP%\sccmXmlReader.tmp"), True)

' Loop thru arguments
For i = 0 to WScript.Arguments.Count-1
	sOut = sOut & Wscript.Arguments(i) & VbCrLf
	' Write to file
	oFile.WriteLine Wscript.Arguments(i)
Next
' Close the file
oFile.Close

' Type the file to the clipboard
oShell.Run oShell.ExpandEnvironmentStrings("%SystemRoot%\System32\cmd.exe /c type %TEMP%\sccmXmlReader.tmp | %SystemRoot%\System32\clip.exe"), 1, True

' Delete the file
oFso.DeleteFile oShell.ExpandEnvironmentStrings("%TEMP%\sccmXmlReader.tmp"), True

' Send a message to the user
MsgBox sOut, vbOKOnly, "Copied to clipboard"

Will try to do a post about how to find the SUB’s…

Comments are closed.