Shaun Cassells at MyITForum.com

SMS 2003 and ConfigMgr 2007, PowerShell, Scripting, Finance, Fitness and Fun

SMS 2003 Client Health Startup Script v4.19

A few bug fixes.

Thanks very much to Hector Cortez: http://myitforum.com/cs2/blogs/hcortez/default.aspx

Version 4.19: http://myitforum.com/cs2/blogs/scassells/Public_SMS_CLIFIX_4.19.vbs.txt

Orginal Article: http://myitforum.com/cs2/blogs/scassells/archive/2009/01/28/sms-2003-client-health-startup-script-v4-18.aspx

Comments

speedyb said:

Hello Shaun,

I was using the script up to version 4.11 from dudeworks. Since we love the working of the script I was please to find that development is continued for this script.

I have 2 questions:

Question 1:

You don't use a fixed site code.

[quote]

'AUTO because AD is extended with servers published

WKS_ASSIGNSITECODE = "AUTO"

[/quote]

Doesn't this mean that traveling users are constantly reassigned between different SMS / SCCM Sites, or must I then use a fixed WKS_ASSIGNSITECODE?

Question 2:

With SCCM when using OS Deployment the client is assigned to the site which the server PXE Booted from. In our environment we have 2 servers in line. Primary1 is our management server which we used to manage the environment. This server also handles PXE. Primary2 is the site which all clients are assigned to. When we use the startup script to asign all clients ( fixed or AUTO ) the deployment fails with a BSOD. Is there a way to prevent this reassignment when an installation is ongoing?

I hope you can help me with these questions. I think I might have a solution for question 2, but I don't know the usability of it. This is my solution based on script 4.11

' =============================================================================

' Method:       CHK_InstallationComplete

' Description:  Checks if the installation of the machine is complete.

'BSt: 20090615

' If the machine is currently installing the installation will fail. Added a check to prevent this.

' The script will check the following:

' * Current site is S50 = Installation Site

' * the folder c:\_SMSTaskSequence is non existing

'

Dim PXEInstallationSite = "S01"

=============================================================================

Sub CHK_InstallationComplete()

COLLECTMSG "CHK_InstallationComplete",">",Null

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\SMS\Mobile Client"

strValueName = "AssignedSiteCode"

oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,CURAssignedSite

If CURAssignedSite = PXEInstallationSite Then

if objFSO.FolderExists("c:\_SMSTaskSequence") then

COLLECTMSG "CHK_InstallationComplete","Installation Status | Still Installing",Null

installationComplete = false

Else

COLLECTMSG "CHK_InstallationComplete","Installation Status | Installation Complete",Null

installationComplete = True

End If

End if

End Sub

Looking forward to hear you opinion about this solution.

Regards,

Bas Steelooper

# June 15, 2009 2:35 PM

speedyb said:

Did some more hobbying arround and came up with the following

Made changes are:

If WKS_ASSIGNSITECODE is not equal to AUTO have the sitecode set in the client to the requested

If the installation is still ongoing in a different site ( PXEInstallationSite ) the reassignment will not occur and the script will exit.

' =============================================================================

' Method:       CHK_ASSIGNMENT

' Description:  Checks Client Site Assignment

Dim PXEInstallationSite = "S01"

' =============================================================================

Sub CHK_ASSIGNMENT

On ERROR Resume Next

Err.clear

COLLECTMSG "CHK_ASSIGNMENT",">",NULL

Dim oSMSClient

Set oSMSClient = CreateObject ("Microsoft.SMS.Client")

If err.Number<>0 Then

COLLECTMSG "CHK_ASSIGNMENT","ERROR", Err.description

COLLECTMSG "CHK_ASSIGNMENT","Could not create SMS Client Object - Quitting", Null

Else

' BSt modification start

Dim mySMSSite

mySMSSite = oSMSClient.GetAssignedSite

if mySMSSite = PXEInstallationSite and objFSO.FolderExists("c:\_SMSTaskSequence") then

wscript.quit

End if

' BSt modification end

If Len(mySMSSite) = 0 Then

CLIENTSTATE = CLIENTSTATE + 1

RegCounter "CHK_ASSIGNMENT",1

If WKS_ASSIGNSITECODE = "AUTO" Then

'have the client determine from AD or SLP appropraite site code

oSMSClient.ReAssignSite

COLLECTMSG "CHK_ASSIGNMENT", "Error - Client not installed correctly - Setting AUTO", Null StrERRType=StrERRType & "ASSIGNMENT_"

Else

oSMSClient.SetAssignedSite(WKS_ASSIGNSITECODE)

COLLECTMSG "CHK_ASSIGNMENT", "Error - Client not installed correctly - Setting " & WKS_ASSIGNSITECODE, Null StrERRType=StrERRType & "ASSIGNMENT_"

End If

    Else

    COLLECTMSG "CHK_ASSIGNMENT",">", "Assigned Site = " & oSMSClient.GetAssignedSite

End If

End If

Set oSMSClient=Nothing

End Sub

# June 19, 2009 3:49 AM

speedyb said:

Hello,

Found a little problem in the script. XP 64Bits is not supported and the select case was not fully functional.

This is the new select for the getOS function

=====

Select Case sOSversion

Case "6.1"

Os = "Windows 7"

isOS="workstation"

Exit Sub

Case "6"

Os = "Vista"

isOS="workstation"

Exit Sub

Case "5"

OS= "2000"

isOS="workstation"

Case "5.1"

Os = "XP"

isOS="workstation"

Exit Sub

Case "5.2"

if sOSProductName = "Microsoft Windows XP" then

Os = "XP 64 Bits"

isOS="workstation"

Exit Sub

else

Os = "2003"

isOS="server"

WSHShell.LogEvent EVENT_INFORMATION, "SMS STARTUP SCRIPT - Do not run on servers@ " & Now

COLLECTMSG "GetOs","ERROR", "Server OS Quiting"

CleanUp(err)

Exit Sub

End If

End Select

=====

# October 19, 2009 5:28 AM

jdavis375 said:

I noted in your script (v. 4.19) you set the initial value of the "CLIENTSTATE" variable to 0. In the original client health script from DudeWorks (v 4.11), the initial value of that variable is 1.

Which should this be? It makes sense that it should be "0", but I wanted to make sure.

Also, in use at another client, a friend of mine noted that there is an error on line 559...there is an extraneous "End if" that was causing the script to error out.

thanks again for your work on the script. It really is fantastic.

# November 23, 2009 6:22 PM

Shane said:

The GetOS function doesn't seem 100% correct as suggested by someone else with the problem with 64-bit XP.

Is the first few lines correct?

sOStype = WSHShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\ProductOptions\ProductType")

sOSversion = WSHShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion")

sOSType = Trim(sOSversion)

You get the ProductType, the CurrentVersion, and then set the ProductType to equal the trimmed value of CurrentVersion.

Perhaps the following would work better and more correctly???? Disclaimer: I'm not a programmer.

Sub GetOs()

           On ERROR Resume Next

           COLLECTMSG "GetOs",">", Null

           Err.clear

           sOStype = WSHShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\ProductOptions\ProductType")

           sOSversion = WSHShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion")

           sOSversion = Trim(sOSversion)

           If Err <> 0 Then

                       CLIENTSTATE = CLIENTSTATE + 1

                       GetOsVersionNumber = "Unknown NTx" ‘Where else is GetOSVersionNumber used?

                       ' Could not determine NT version

                       Exit Sub ' >>>

           End If

           Select Case sOSversion

                       Case 6.1

                                   If sOStype="WinNT" Then Os = "Windows 7"

                                   If sOStype="WinNT" Then IsOS ="workstation" Else IsOS ="server"

                                   Exit Sub

                       Case 6

                                   If sOStype="WinNT" Then Os = "Vista"

                                   If sOStype="WinNT" Then IsOS ="workstation" Else IsOS ="server"

                                   Exit Sub

                       Case 5

                                   If sOStype="WinNT" Then Os= "2000"

                                   If sOStype="WinNT" Then IsOS ="workstation" Else IsOS ="server"

                                   Exit Sub

                       Case 5.1

                                   If sOStype="WinNT" Then Os = "XP"

                                   If sOStype="WinNT" Then IsOS ="workstation" Else IsOS ="server"

                                   Exit Sub

                       Case 5.2

                                   If sOStype="WinNT" Then Os = "XPx64"

                                   If sOStype="WinNT" Then IsOS ="workstation" Else IsOS ="server"

                                   Exit Sub

           End Select

End Sub

# January 14, 2010 1:20 AM