if (length == 1) {
$.Echo(text);
}
else {
var i = 1;
for (; i < length; i++) {
if ((object = arguments[i]) != null) {
var append = !object ? "" : (!(object.toString) ? "ActiveXObject {...}" : object.toString());
$.Echo(text + append);
}
else {
$.Echo(text);
}
}
}
};
var ASSERT = function (condition, message, ignore) {
if (condition === false) {
PRINT("!! " + message);
if (!ignore) {
EXIT(-1);
}
}
};
var MEF = (function () {
var toString = Object.prototype.toString;
var exporters = {};
var instances = {};
var class2type = {};
var MEF = function (selector, context, options) {
// The MEF object is actually just the init constructor 'enhanced'
return new MEF.fn.init(selector, context, options);
};
var EXPORT = function (name, ctor) {
exporters[name] = ctor;
instances[name] = undefined;
};
var EXISTS = function (selector) {
if (!selector) {
return false;
}
else if (typeof selector === "string") {
var ctor = exporters[selector];
if (!ctor) {
return false;
}
return true;
}
else {
return false;
}
};
var IMPORT = function (selector, context, options) {
if (!selector) {
return undefined;
}
else if (typeof selector === "string") {
var ctor = exporters[selector];
if (!ctor) {
if (context == false) {
throw selector + " not exported!";
}
else {
return undefined;
}
}
return ctor.call(options);
}
else {
throw selector + " not supported!";
}
};
MEF.fn = MEF.prototype = {
Value: function (newVal) {
if (newVal != undefined) this._Value = newVal;
return this._Value;
},
init: function (selector, options) {
// global, can only query by string
if (selector != undefined && typeof selector === "string") {
var value = instances[selector];
if (value === undefined) {
value = IMPORT(selector, false, this.extend({
name: "#" + selector,
Value: function () {
return this._Value;
}
}));
if (value != undefined) {
instances[selector] = value;
}
}
return value;
}
else if (selector != undefined) {
return MEF.extend(selector, this);
}
else {
return undefined;
}
},
each: function (callback) {
MEF.ForEach(this.call(this), callback);
},
first: function () {
var retVal;
MEF.ForEach(this.call(this), function () {
retVal = this;
return false
});
return retVal;
},
to_s: function () {
var v = this.Value();
if (v == undefined) {
return "null";
}
else {
return ":" + v.toString();
}
}
}
// Give the init function the MEF prototype for later instantiation
MEF.fn.init.prototype = MEF.fn;
MEF.extend = MEF.fn.extend = function () {
var options, name, src, copy, copyIsArray, clone, target = arguments[0] || {},
i = 1,
length = arguments.length,
deep = false;
// Handle a deep copy situation
if (typeof target === "boolean") {
deep = target;
target = arguments[1] || {};
// skip the boolean and the target
i = 2;
}
// Handle case when target is a string or something (possible in deep copy)
if (typeof target !== "object" && !MEF.isFunction(target)) {
target = {};
}
// extend MEF itself if only one argument is passed
if (length === i) {
target = this;
--i;
}
for (; i < length; i++) {
// Only deal with non-null/undefined values
if ((options = arguments[i]) != null) {
// Extend the base object
for (name in options) {
src = target[name];
copy = options[name];
// Never move original objects, clone them
target[name] = MEF.extend(deep, clone, copy);
// Don't bring in undefined values
} else if (copy !== undefined) {
target[name] = copy;
}
}
}
}
// Return the modified object
return target;
};
MEF.extend({
version: "1.0.0",
Arguments: $.Arguments,
WriteLine: PRINT,
Assert: ASSERT,
Exists: EXISTS,
Export: EXPORT,
Import: function (selector, options) {
// context, query by string or undefined
var val = new MEF.fn.init(undefined);
return IMPORT(selector, true, val.extend(options));
},
Value: function (selector, value) {
instances[selector]._Value = value;
},
// args is for internal usage only
ForEach: function (object, callback, args) {
var name, i = 0,
length = object.length,
isObj = length === undefined || MEF.isFunction(object),
isCom = isObj && !object.toString;
if (args) {
if (isObj) {
for (name in object) {
if (callback.apply(object[name], args) === false) {
break;
}
}
} else {
for (; i < length;) {
if (callback.apply(object[i++], args) === false) {
break;
}
}
}
// A special, fast, case for the most common use of each
} else {
if (isCom) {
var e = new Enumerator(object);
for (; !e.atEnd(); e.moveNext()) {
value = e.item();
if (callback.call(value, i++, value) === false) {
break;
}
}
}
else if (isObj) {
for (name in object) {
if (callback.call(object[name], name, object[name]) === false) {
break;
}
}
} else {
for (var value = object[0];
i < length && callback.call(value, i, value) !== false; value = object[++i]) {}
}
}
return object;
},
Dump: function (object) {
MEF.ForEach(object, function(key, value) {
if (typeof value !== "object" && !MEF.isFunction(value)) {
PRINT(" ", key);
PRINT("", value);
}
});
},
// string helpers
Trim: function (str, whitespace) {
if (str == null) {
return null;
}
else if (!whitespace) {
return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
else {
for (var i = 0; i < str.length; i++) {
if (whitespace.indexOf(str.charAt(i)) === -1) {
str = str.substring(i);
break;
}
}
for (i = str.length - 1; i >= 0; i--) {
if (whitespace.indexOf(str.charAt(i)) === -1) {
str = str.substring(0, i + 1);
break;
}
}
return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}
},
EqualsIgnoreCase: function (left, right) {
if (left == null || right == null) {
if (left == null && right == null) {
return true;
}
else {
return false;
}
}
return left.toUpperCase() == right.toUpperCase();
},
Format: function (frmt, args) {
for (var x = 0; x < arguments.length; x++) {
frmt = frmt.replace("{" + x + "}", arguments[x + 1]);
}
return frmt;
},
IsNullOrEmpty: function (str) {
if (!str)
{
return true;
}
// type check
type: function (obj) {
return obj == null ? String(obj) : class2type[toString.call(obj)] || "object";
},
isFunction: function (obj) {
return MEF.type(obj) === "function";
},
isArray: Array.isArray ||
function (obj) {
return MEF.type(obj) === "array";
},
isPlainObject: function (obj) {
// Must be an Object.
// Because of IE, we also have to check the presence of the constructor property.
// Make sure that DOM nodes and window objects don't pass through, as well
if (!obj || MEF.type(obj) !== "object" || obj.nodeType || MEF.isWindow(obj)) {
return false;
}
// Not own constructor property must be Object
if (obj.constructor && !hasOwn.call(obj, "constructor") && !hasOwn.call(obj.constructor.prototype, "isPrototypeOf")) {
return false;
}
// Own properties are enumerated firstly, so to speed up,
// if last one is own, then all properties are own.
// Populate the class2type map
MEF.ForEach("Boolean Number String Function Array Date RegExp Object".split(" "), function (i, name) {
class2type["[object " + name + "]"] = name.toLowerCase();
});
$.Export("WMI.Query", function () {
this._Value = [];
return $.extend(function () {
var order = (!this.Sorted) ? "" : " ORDER BY " + this.Sorted;
var where = (!this.Condition) ? "" : " WHERE " + this.Condition;
var values = this.WMI.WmiServer.ExecQuery("SELECT * FROM " + this.ClassName + order + where);
$.Export("Mom.ScriptAPI", function () {
return scriptAPI != undefined ? scriptAPI : WScript.CreateObject("Mom.ScriptAPI");
});
$.Export("DiscoveryData", function () {
return $("Mom.ScriptAPI").CreateDiscoveryData(0, sourceId, managedEntityId);
});
$.Return = function (value) {
$("Mom.ScriptAPI").Return(value);
};
$.Export("ConfigMgr", function () {
var siteCode = $("CIMv2").GetRegistryStringValue("SOFTWARE\\Microsoft\\SMS\\Identification", "Site Code");
var siteId = $("CIMv2").GetRegistryStringValue("SOFTWARE\\Microsoft\\SMS\\Identification", "Site ID");
var siteWmi = $.Import("WMI").TryConnect(siteServer, "root\\sms");
var sdkProv;
var providerLocation;
if (siteWmi === undefined) {
var parentSiteCode = $("CIMv2").GetRegistryStringValue("SOFTWARE\\Microsoft\\SMS\\Identification", "Parent Site Code");
var parentSiteServer = $("CIMv2").GetRegistryStringValue("SOFTWARE\\Microsoft\\SMS\\Identification", "Parent Server");
if (parentSiteServer.length === 0) {
var sqlServer = $("CIMv2").GetRegistryStringValue("SOFTWARE\\Microsoft\\SMS\\SQL Server", "Server");
var database = $("CIMv2").GetRegistryStringValue("SOFTWARE\\Microsoft\\SMS\\SQL Server", "Database Name");
// If we are using sql named instance
if (database.indexOf("\\") !== -1) {
var databaseArray = database.split("\\");
sqlServer = sqlServer + "\\" + databaseArray[0];
database = databaseArray[1];
}
var sqlConnection = new ActiveXObject("ADODB.Connection");
var connectionString = "Data Source=" + sqlServer + ";Initial Catalog=" + database + ";Integrated Security=SSPI;Provider=SQLOLEDB";
sqlConnection.Open(connectionString);
var result = new ActiveXObject("ADODB.Recordset");
result.Open("select TOP(1) ServerRemoteName from sysreslist where RoleName = 'SMS Site Server' and SiteCode = '" + parentSiteCode + "'", sqlConnection);
result.MoveFirst;
while (!result.eof) {
parentSiteServer = result.fields(0).Value;
result.MoveNext;
}
result.close;
sqlConnection.close;
}
$.Export("CIMv2", function () {
var cimWmi = $.Import("WMI").Connect(siteServer, "root\\cimv2");
var defaultWmi = $.Import("WMI").Connect(siteServer, "root\\default");
var HKLM = 0x80000002;
return cimWmi.extend({
CurrentServer: siteServer,
GetRegistryStringValue: function (strKeyPath, strValueName) {
var value = defaultWmi("StdRegProv").Execute(
"GetStringValue",
function () {
this.sSubKeyName = strKeyPath;
this.sValueName = strValueName;
return this;
},
function () {
if (this.ReturnValue == 0) {
return this.sValue;
}
else {
return undefined;
}
});
return value;
}
});
});
})($, $.Import("Mom.ScriptAPI"));
(function ($, undefined) {
$.Export("ConfigMgr.RoleClassMap", function () {
var map = {};
// 11-15
map["SMS_Server_Locator_Point".toUpperCase()] = "ConfigMgr Server locator point";
map["SMS_Site_Server".toUpperCase()] = undefined;
map["SMS_Site_System".toUpperCase()] = undefined;
map["SMS_SQL_Server".toUpperCase()] = "ConfigMgr Site database server";
map["SMS_State_Migration_Point".toUpperCase()] = "ConfigMgr State migration point";
// 16-20
map["SMS_System_Health_Validator".toUpperCase()] = "ConfigMgr System Health Validator point";
map["SMS_Software_Update_Point".toUpperCase()] = "ConfigMgr Software update point";
map["AI_Update_Service_Point".toUpperCase()] = "ConfigMgr Asset Intelligence Synchronization";
map["SMS_Multicast_Service_Point".toUpperCase()] = "ConfigMgr Multicast service point";
map["SMS_AMT_Service_Point".toUpperCase()] = "ConfigMgr Out of band service point";
// this is a site role, not a component
map["SMS_SITE_COMPONENT_MANAGER".toUpperCase()] = undefined;
map["SMS_SITE_SYSTEM_STATUS_SUMMARIZER".toUpperCase()] = "$MPElement[Name='SCCM!Microsoft.SystemCenter2012.ConfigurationManager.SiteSystemStatusSummarizer']$";
map["SMS_STATE_MIGRATION_POINT".toUpperCase()] = "$MPElement[Name='SCCM!Microsoft.SystemCenter2012.ConfigurationManager.StateMigrationPointControlManager']$";
map["SMS_STATE_SYSTEM".toUpperCase()] = "$MPElement[Name='SCCM!Microsoft.SystemCenter2012.ConfigurationManager.StateSystem']$";
map["SMS_SITE_COMPONENT_MANAGER".toUpperCase()] = undefined;
map["SMS_SITE_SYSTEM_STATUS_SUMMARIZER".toUpperCase()] = "ConfigMgr Site System Status Summarizer";
map["SMS_STATE_MIGRATION_POINT".toUpperCase()] = "ConfigMgr State Migration Point";
map["SMS_STATE_SYSTEM".toUpperCase()] = "ConfigMgr State System";
map["SMS_WAKEONLAN_MANAGER".toUpperCase()] = "ConfigMgr Wake on Lan Manager";