In a comment to my response to this question , cop1152 said he loved WMI scripts. Well, so do I!
What are your favourite, best, most useful scripts you'd like to share with the community?
thanks.
|
In a comment to my response to this question , cop1152 said he loved WMI scripts. Well, so do I! What are your favourite, best, most useful scripts you'd like to share with the community? thanks. | ||||
|
feedback
|
|
One I wrote to help a colleague, who RDPd to a server, opened Event Viewer, looked through it for errors. Then repeated for the other 3 servers... every day.
| ||||
|
feedback
|
|
One of my favs (because it was my first) that gave me the most trouble...that I wrote over and over and over until it worked correctly....was a script that remotely 'disabled' our homemade web-filter. We use a 'customized' (by me) version of Squid with some freely available blacklists to content filter and block ports on our public machines (I work for a med-sized, 3-branch public library system). The WMI script runs on a staff machine. Once a staff member executes it he/she is prompted to select which machine to disable the filter. When the script executes, essentially it removes the check mark from the proxy setting opions in Internet Explorer, at the registry level. The filter is enabled by a batch file that fires off when the patrons session is up and the computer auto logs off and back on. We ended up using my WMI only on a few test machines, but I really enjoyed learning how almost anything can be accomplished with WMI. | |||||
|
feedback
|
|
Script is useful and iam able to execute this. But the file is only showing the information like ========================================== Data: InsertionStrings:
More over ("EventView_" & today & ".log") this file is just creating the file with EventView_00.log not with actual date. As per the syntax it should give data instead off )00 . | ||||
feedback
|
|
From WSH JScript:
// List errors from Windows EventLog (filter only errors from last month).
function leadingzero(str) {
if (str.length == 1)
return "0"+str;
else
return str;
}
function good_date(d) {
var dstr = d.getFullYear().toString();
dstr += leadingzero((d.getMonth()+1).toString());
dstr += leadingzero(d.getDate().toString());
dstr += leadingzero(d.getHours().toString());
dstr += leadingzero(d.getMinutes().toString());
dstr += leadingzero(d.getSeconds().toString());
dstr += ".000000-000";
return dstr;
}
// 24*3600*1000 - one day
// 30*24*3600*1000 - one month
time = good_date(new Date(new Date() - 30*24*3600*1000));
var wbemFlagReturnImmediately = 0x10;
var wbemFlagForwardOnly = 0x20;
var objWMIService = GetObject("winmgmts:\\\\.\\root\\CIMV2");
var items = objWMIService.ExecQuery("SELECT * FROM Win32_NTLogEvent WHERE (Type = 'Ошибка' OR Type = 'Error') AND TimeGenerated > '" + time + "'",
"WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly);
var enumItems = new Enumerator(items);
for (enumItems.moveFirst(); !enumItems.atEnd(); enumItems.moveNext()) {
var i = enumItems.item();
WScript.Echo("Type: " + i.Type + "\n" + "Message: " + i.Message + "\n" + "TimeGenerated: " + i.TimeGenerated);
}
| ||||
|
feedback
|