Skip to content

Posts from the ‘Scripts’ Category

14
Jun

Windows Update Agent force script, email results version 2.6

via [Spiceworks Community Script Center]

This script (the core was pulled from Microsoft’s website, and the WindowsUpdate agent install was borrowed from Torgeir Bakken – thank you!) will tell the WU Automatic Update Client (wuaclt.exe) to ‘detectnow’, download and install missing windows updates as compared to it’s update server. Works for WSUS and regular Windows Update site.

You can force a client to restart after the updates have been applied (if a reboot is pending, or if you plain just want to restart for the heck of it).

The script is highly configurable, and should fit most applications where users/admins need to force a download and installation of approved updates.

NOTE: If there are a LOT of downloads to pull, the status window (or log) will say “Downloading” for that entire time. I’m not sure how to get a download progress of each update…maybe someone can help me with that.

Note on command-line switches: If you don’t specify a switch (for example, ‘email:’) the corresponding variable defined in the script will provide the needed information (command-line switches take precedence).

Why I put this script together:

Our desktop deployment technicians needed a script that would pull updates immediately and install.

We have some computers that are sometimes logged on or not (but they run services that must be running almost constantly), and are never rebooted.

The user ignores the ‘you have new updates available’ message, so updates are never installed. This script will let you install the updates, and then it tells the WUA to present the ‘restart’ message – which more users are apt to respond to.

If the client running the script doesn’t have the 2.0 WUA installed, Torgeir’s portion of the script will automatically install it (please contact me if this doesn’t work – I modified his script slightly to plug into mine!).

After the script runs, it will email a recipient the resulting logfile that is produced. Very handy for running with my Front-end to PSEXEC tool.

You need to edit the following variables:

* sExePath – this is the location of the WindowsUpdateAgent20-x86.exe. Download it from http://go.microsoft.com/fwlink/?LinkId=43264
* strMailFrom – arbitrary reply-to address
* strMailto – email address you want the report to mail to (this is for manual mode – or if the command-line switch isn’t specified).
* strSMTPServer – the IP address of the email server you are sending the reports through.

Optional variables:

  • Silent: 0 = verbose, 1 = silent (no windows or visible information)
  • Intdebug: 0 = off, 1 = 1 (see some variables that are being passed)
  • strAction: prompt|install|detect. Prompt gives users opportunity to install updates or not, install just installs them, detect updates the WU collection and downloads the updates (but does not install them) – useful if you want to have the computer refresh its stats to the stat server but not install the updates.
  • blnEmail:  0 = off|1 = on. If set to 0, the script will not email a log file. If you specify an email address in the command-line, this will force the script to switch blnEmail to ‘1′.
  • strRestart: 0 = Do nothing|1 = restart|2 = shutdown. Command-switch ‘restart:’ supercedes this variable.

Command line switches:

  • action: prompt|install|detect
  • mode: silent|verbose
  • email: you@yourdomain.com
  • restart: 0 (do nothing)| 1 (restart) | 2 (shutdown)
  • force: 0 (do not enforce restart action – this is optional, by default it is set to 0) | 1 (enforce restart action)
  • emailsubject: – Text for custom subject enclosed in quotations (i.e. “This is a custom subject”
  • fulldnsname: 0 (use non-qualified server name) | 1 (use fully qualified DNS name of the server that the script ran on)
  • emailifallok: 0 (don’t email a report if there are no problems with the update process) | 1 (email report whether there are errors or not)
  • smtpserver: x.x.x.x or smtp mail hostname (define an alternate SMTP server)
  • logfile: “x:\path\log.txt”
  • authtype: cdoAnonymous|cdoNTLM|cdoBasic (SMTP authentication type)
  • authID: userid (SMTP authentication ID)
  • authPassword: password (SMTP authentication password)

Finally, rename the file with .vbs extension

Example of usage:

Action Command-line
Install updates silently, email you a logfile, then restart the computer updatehf.vbs action:install mode:silent email:you@yourdomain.com restart:1
Detect missing updates, email you a logfile, then do nothing (no restart) updatehf.vbs action:detect mode:verbose email:you@yourdomain.com restart:0
Prompt user to let them decide whether or not to install updates, email you a logfile, prompt user for restart updatehf.vbs action:prompt mode:verbose email:you@yourdomain.com restart:1
Install updates silently, email you a logfile, then shutdown the computer if a reboot is pending-> updatehf.vbs action:install mode:silent email:you@yourdomain.com restart:2
Install updates silently, email you a logfile, then shutdown the computer no matter if a reboot is pending or not-> updatehf.vbs action:install mode:silent email:you@yourdomain.com restart:2 force:1
Detect missing updates or pending reboot silently, email you a logfile, then restart if there is a pending reboot -> updatehf.vbs action:detect mode:silent email:you@yourdomain.com restart:1
Detect missing updates or pending reboot silently, email you a logfile, then restart no matter if there is a pending reboot -> updatehf.vbs action:detect mode:silent email:you@yourdomain.com restart:1 force:1

Download it from the Spiceworks Community Script Center

updatehf.vbs action:install mode:silent email:you@yourdomain.com restart:2 force:1
14
Jun

Edit an XML node and save a file with VBScript

Quick example of editing an XML node with a VBScript.

Let’s say we need to update the \\server\value with a new server/share combination.

XML:

<configdata>

<FaxInBox>\\server\value</FaxInBox>

</configdata>


VBSCRIPT:


on error resume next

‘Define what our new value will be and place it into a variable
sValue = “\\server\inbox”

‘Get path of script, (scriptfullname), then replace the scriptname with nothing  bring us only the path and place it into strScriptPath
strScriptPath = replace(wscript.scriptfullname,wscript.scriptname,”")

‘Create XMLDoc object
Set xmlDoc = CreateObject(“Microsoft.XMLDOM”)

‘load up the XML file and place it into xmldoc
xmlDoc.load strScriptPath & “configuration.xml”

‘Select the node we want to edit
‘The text IS case sensitive
Set sInboxFolder = xmlDoc.selectsinglenode (“//configdata/FaxInBox”)

‘Show the current value in FaxInBox
‘msgbox sInboxFolder.text

‘Set the text node with the new value
sInboxFolder.text = sValue

‘Save the xml document with the new settings.
iResult = xmldoc.save(strScriptPath & “configuration.xml”)

You can use the iResult as a way to determine if the file gets saved correctly or not (‘0=yes’, ‘1=no’)

23
Apr

VBScript goodness: The modular logon script

Shortcut to the documentation: http://community.spiceworks.com/how_to/show/1189

Download the script http://bit.ly/c83ifo

lego

I know a lot of people don’t like messing about with logon scripts – it can get annoying and tedious – especially if you are writing them for different departments, but only want to maintain a small handfull (or one!) of scripts.

Typically, these scripts are batch files, and many times, you find out you are stuck when you need to put something in place that checks for group membership, so something only runs for a particular person (or group of people).

Why you would want to use the modular logon script:

Sue wants to map the marketing drive, but only for those employees that are actually in the marketing group.

Jerry wants to have printers automatically mapped to him on the lab computers, but not on his office computer.

Eric has additional files that need to be copied to a folder on his computer, but only when he logs on, and it could be on any computer.

Kevin logs into a computer and wants a particular process to run when the IP address is 192.168.0.23.

I’ve been working hard on a nifty solution that handles a good portion of logon needs – a modular VBScript-based logon script.  This script has a few handy benefits over a typical batch script:

  • Changing configuration files for the logon script is much easier than batch files
  • Full logging capability is built-in, writing to the user’s temp folder
  • Users can run simultaneous logon scripts at once, such as in a nested OU structure
  • One can edit the configuration file with little fear of breaking the main core logon script
  • Drives and printers can be mapped or removed based upon group/OU memberships
  • Include snippets of VBScript code based upon group/OU membership
  • You can still run legacy batch files if need be

The need for this script ultimately came about from having multiple computers needing certain printers mapped, no matter who was logged in.  These computers have a specific purpose, but the logons may differ.  However, no matter who logs in, they still want to print to the lower-level hallway printer.

I decided to put together this script which could be run in a variety of scenarios and have the scalability to grow with our business, but yet retain a simple method of updating and maintaining.  The real beauty in the script lies in the sheer simplicity in how to map resources such as printers and drives.  Just insert the path of your printer in the ‘printers’ section – or the drive letter and path to the share in the ‘drives’ section.  Easy.  No ‘Net Use’ commands, no complex VBScript (to some) functions to remember.

Here’s an example of a configuration file that you would pass to the logon.vbs file.

<order>
meta=1
drives=3
printers=2
processes=4
include=5
</order>

<meta>
description=For all users
created=02/09/10
author=Rob Dunn</meta>

<drives>
m:\\server\marketing|group:marketing
p:\\server\sUser
rem z:\\server\share
</drives>

<printers>
\\server\pdfcreator;default|group:Print Users
\\server\hpprinter|group:Print Users
\\server\colorprinter|-group:domain users|group:Colorprint Users
\\server\faxprinter|ip:192.168.0.23
</printers>

<processes>
c:\windows\write.exe
</processes>


<include>
File1.inc
File2.inc|computerOU:OU=test,OU=domain computers
File3.inc|group:marketing
</include>