Friday, April 11, 2008

Just a heads up to whomever may find this blog...

Phil and I have both moved on in our careers and the updates to this blog have ceased. Phil has shifted focus more to the application developement side of IT, I have shifted focus to the implementation of the System Center products.

I will be maintaining a new blog focused primarily on System Center Operations Manager & Configuration Manager, and to a degree application packaging. My new blog can be found here:

http://systemcenterinfo.blogspot.com/

It is newly created as of today, however it will be updated frequently as I encounter new solutions and behaviors of SCCM/OpsMgr. Stop by and check it out.

Regards,
Will Kaiser

Wednesday, December 13, 2006

Query: Build collection to exclude members of another collection

This has proven to be quite useful. Here's how to create a query-based collection that will exclude members of another collection:

1. Create a collection that will contain all clients to be excluded from another collection (we'll call it 'ExclusionsCollection' for this example.)

2. Once you have that, go into the Collections table in the SMS SQL database and find the row that contains 'ExclusionsCollection'. Note the cooresponding 'ResultTableName'.

3. In the collection that you want to exclude the members of 'ExclusionsList' from, copy and paste the following query:

select SMS_R_System.ResourceID,SMS_R_System.ResourceType,
SMS_R_System.Name,SMS_R_System.SMSUniqueIdentifier,
SMS_R_System.ResourceDomainORWorkgroup,SMS_R_System.Client
from SMS_R_System where Client = 1 and ClientType = 1 and
ResourceId not in (select ResourceID from SMS_CM_RES_COLL_XXXxxxxx)

4. Replace the item above in red with your ResultTableName.

So, machine will be manually entered into 'ExclusionsCollection' will be excluded from the collection with the above query. So say that you wanted to deploy a package to all XP machines except for a specific few, you'd create a collection and limit it to the 'All XP Machines' collection, and then add the above query.

Friday, October 06, 2006

SMS: Useful...stuff

Here's a few useful things to note when deploying packages:

- Use "CMD.EXE /C" in front your command to run it from the command prompt.

- Need to apply a patch to an application that you are deploying, but need a reboot in between? Try creating 2 advertisements, one for the main application and one for the patch. Set the main application install to run as soon as possible and set the patch to run at Logon. The machine will not receive the second advertisement until after they next log on to their machine.

- When deploying an MSI file use the ‘Create package from definition’ option. This will create attended and unattended installation programs, as well as an uninstall program.

- Good practice: Build an uninstall program for your package when you build the install program. You’ll thank yourself later when you don’t have to spend a few hours testing the install and determining the best route to uninstall.

- Suppress the annoying reboot notification box that still appears after a patch installation, even though the reboot has been suppressed with this command: net stop wuauserv

- A word on patches. In the event that your environment has a large number of individual patch packages with individual advertisements, try rolling all the patches into a single package with a single advertisements. The reason? The patch management system in SMS is intelligent enough to roll numerous patches into a single install. So in effect, if you have 15 patches in 15 packages with 15 associated advertisements, new clients in the environment are going to experience quite a bit of processing overhead b/c of those advertisements. Take those 15 patches and roll them into a single package with a single advertisement, and clients will install the patches faster and experience less of a slow-down.

Thursday, October 05, 2006

Microsoft will police licenses through SMS

Microsoft is beefing up policing for Windows licensing after going back to the drawing board on its asset management strategy.

Upcoming editions of Systems Management Server (SMS) will introduce metadata and workflow tools and capabilities for management of software licenses in a three-phase plan....

Read the full article here.

Saturday, September 30, 2006

WMI - Scripting

In my previous entry, WMI - Introduction I covered the basics of how WMI worked and how to write a simple script utilizing WMI technology. Today we will cover some more in depth information regarding WMI and scripting, along with some more advanced WMI queries.

WMI Classes

Introudction to Object-Oriented Programming & Classes

The concept of classes within WMI is borrowed from object-oriented programming, object-oriented programming was born in the 60's and the first programming language implementing the idea of classes was Simula 67. SmallTalk, which was developed at Xerox, took the idea even further by using objects to represent everything, becoming the first "pure" object-oriented language. The fundamental concept to understand about object-oriented programming is that an object represents an instance of a physical or logical thing. In effect we can then represent a car as an object. All cars have similar properties, they have four wheels, seats, a stearing wheel, a gas petal... They also can do similar things such as accellerate, slow down, turn... We represent these definitions of an object in a blueprint called a class.

A class is a logical representation of an object that defines what properties an object has and also what an object can do. Properties represent characteristics of an objects and methods represent what an object can do. Once we have a class, or blueprint, to use we can create an instance of this class, the instance is what we refer to as an object.

It is not neccessary to have a full understanding of object-oriented programming to work with WMI and VBScript, however a solid understanding of the fundamentals will greatly aide your ability to comprehend how the internals of WMI work as well enable you to understand how VBScript objects interact and work together.

Object-Oriented Internet Resources
WikiPedia Object-Oriented Programming Article
Object Oriented FAQ
Understanding Object Oriented Programming
OOPSLA (Object-Oriented Programming, Systems, Languages and Applications) International Conference

WMI Classes

WMI classes are symbolic represenations of hardware and software items that a computer has. Nearly everything about your computer is represented in WMI by a class, from DVD-ROM drives to event logs, more than likely there is a class that represents information about your computer that you need access to. WMI classes are almost always created by compiling a MOF (Managed Object Format) file and adding them to the WMI Repository. The exception to this rule is the core system classes. The core system classes, which can be identified by the double underscore (__) preceding their name, are present in all namespaces and built into the foundation of WMI. The core system classes provide the following: Event and provider registration, event notification and security.

Querying WMI and Executing Methods
In the below script we utilize the WMI class Win32_Process . This class is extremely useful as it gives us information to all the processes that are currently running on a local or remote computer system. In the script below we do two things:
  • Query all instances of running processes that match our requirements.
  • Terminate all processes that were returned.

Take a look at the script below, and look through each line code. If you want launch a few copies of notepad on your system and run the script to see how it functions.

Option Explicit

Dim oSWbemServices
Dim sHost
Dim sNamespace
Dim sQuery
Dim oProcessColl
Dim oProcess

sHost = "."
sNamespace = "\root\cimv2"
sQuery = "SELECT Name, ProcessID FROM Win32_Process WHERE Name = 'notepad.exe'"

Set oSWbemServices = GetObject("winmgmts:\\" & sHost & sNamespace)

Set oProcessColl= oSWbemServices.ExecQuery(sQuery)

For Each oProcess In oProcessColl
WScript.Echo "Terminating " & oProcess.Name
WScript.Echo "ProcessID: " & oProcess.ProcessID
oProcess.Terminate
Next


WQL - The WHERE Clause
The first part of this script I would like to take a look at is the WQL query we execute to retreive all the instances of notepad.exe.
SELECT Name, ProcessID FROM Win32_Process WHERE Name = 'notepad.exe'

This query looks basically the same as the query we used in the last article to retreive network adapters, however this one has a couple of significant differences. First instead of using the generic asterik to specify we are retrieving all fields that are defined in the class we specify two fields; Name and ProcessID. This can speed up query execution time as well reduce the overall memory footprint of your script. In general it is a best practice to specify only the class fields that you will use in your script instead of retreiving all fields. The second noteable difference in this query is the addition of the WHERE clause on the end of the script. The WHERE clause acts a filter so that we only return class instances that match our criteria. We therefore are relying on the WMI system to filter out instances accordingly instead of having to do these comparisons our selves. If you are familiar with SQL then the WQL's WHERE clause will feel right at home. For those of you that are not I highly reccommend you checkout the MSDN WQL WHERE Clause entry, or brush up on SQL a little bit. You are not limited to merely to string tests you can combine comparisons of all types of fields that results in a very powerful filtering method.

Executing WMI Class Methods

So we execute our WQL query and retreive a collection of all class instances that have the name "notepad.exe", from here we decide that we must terminate all of these instances. This brings us to the second part of this script which is different from the ones we have previously used. WMI method calling. Earlier we talked about object oriented programming and how the WMI uses the object oriented paradigm to describe data. Many WMI classes have methods that you can call to perform certain operations upon the class instances. As you can see we call the Terminate method to kill any processes that we found matching our query.

Wrap Up & Exercise

Once you understand how to query WMI retrieve and output the results and execute WMI methods you have learned the basics and can develop all sorts of scripts that we help you automate mundane tasks, or acclompish things with SMS that normally would not be possible. For instance let's say your upgrading a software package and due to the requirements the end-user will most likely be logged in to the machine and running the application you need to upgrade. This can be a difficult a thing to accomplish normally but with the power of WMI scripts you can now handle this easily. For a homework exercise I have a little challenge for you:

Investigate the WMI class Win32_Service and write a script that will restart the "Task Scheduler" service on a list of machines you specify in the script. I'll post my script here in a week so stay tuned! I hope you learned a little something new about WMI, and will start to see how great of tool this can be to use in your day to day job.

Resources
WMI Classes Reference
Win32_Process
WQL WHERE Clause
MOF (Managed Object Format)