Tuesday, April 28, 2009

KiXtart Script: Building an MMC Console

This is based on a VBScript example posted a while back by the renown, the incredible, Mr. Don Hite. I mixed in some code from the MSDN MMC Automation object model reference documentation, poured it all into a KiXtart blender and punched the puree button. Be mindful of word-wrapping on the longer strings.

;----------------------------------------------------------------
; Filename..: mmc.kix
; Author....: David M. Stein
; Date......: 04/28/2009
; Purpose...: build and save a custom MMC console
;----------------------------------------------------------------
Break ON

$consoleName = "C:\MyConsole.msc"

If Exist($consoleName)
? "info: console already created as $consoleName"
Else
? "info: console not found, building now..."
$objMMC = CreateObject("MMC20.Application")
$objMMC.Show
$objDoc = $objMMC.Document
$objSnapIns = $objDoc.SnapIns
$objFolder = $objSnapIns.Add("Folder")
$nul = $objMMC.Document.SnapIns.Add("Active Directory Users and
Computers")
$nul = $objMMC.Document.SnapIns.Add("Active Directory Sites and
Services")
$nul = $objMMC.Document.SnapIns.Add("Active Directory Domains
and Trusts")
$objMMC.UserControl = 1
$objMMC.Document.Name = $consoleName
$objMMC.Document.Save()
? "info: console built and saved as $consoleName"
EndIf

No comments: