diff --git a/3044.pdf b/3044.pdf new file mode 100644 index 0000000..d563939 Binary files /dev/null and b/3044.pdf differ diff --git a/3045.pdf b/3045.pdf new file mode 100644 index 0000000..3f00146 Binary files /dev/null and b/3045.pdf differ diff --git a/9781590597125.jpg b/9781590597125.jpg new file mode 100644 index 0000000..4166c05 Binary files /dev/null and b/9781590597125.jpg differ diff --git a/Chapter02/2-1_DisplaySiteBoundaries.vbs b/Chapter02/2-1_DisplaySiteBoundaries.vbs new file mode 100644 index 0000000..5de5848 --- /dev/null +++ b/Chapter02/2-1_DisplaySiteBoundaries.vbs @@ -0,0 +1,28 @@ +Set objArgs = WScript.Arguments +strSMSServer = objArgs(0) +strSiteToDisplay = objArgs(1) + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +strInfo = "Site Boundary Informaiton for Site " & _ + strSiteToDisplay & vbCRLF +Set boundaries=objSMS.Get _ + ("SMS_SCI_SiteAssignment.SiteCode='" & _ + strSiteToDisplay & "',Filetype=1,ItemName='" & _ + "Site Assignment',ItemType='Site Assignment'") + +For i=0 to ubound(boundaries.AssignDetails) + strInfo = strInfo & space(len(descr)) & _ + boundaries.AssignTypes(i) & _ + ": " & boundaries.AssignDetails(i) & vbCRLF +Next +wscript.echo strInfo diff --git a/Chapter02/2-2_AddIPSiteBoundary.vbs b/Chapter02/2-2_AddIPSiteBoundary.vbs new file mode 100644 index 0000000..5379a63 --- /dev/null +++ b/Chapter02/2-2_AddIPSiteBoundary.vbs @@ -0,0 +1,39 @@ +strSMSServer = +strSubnet = "10.5.123.0" 'replace with desired subnet +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.SiteCode + end if +Next + +Set WbemContext=CreateObject("WbemScripting.SWbemNamedValueSet") +WbemContext.Add "SessionHandle", objSMS.ExecMethod _ + ("SMS_SiteControlFile", "GetSessionHandle").SessionHandle +objSMS.ExecMethod "SMS_SiteControlFile.Filetype=1,SiteCode='" _ + & strSMSSiteCode & "'", "Refresh", , , WbemContext +'retrieve boundary details +Set WbemInst = objSMS.Get _ + ("SMS_SCI_SiteAssignment.Filetype=2,Itemtype='Site Assignment'," _ + & "SiteCode='" & strSMSSiteCode & _ + "',ItemName='Site Assignment'", , WbemContext) +proparray1 = WbemInst.AssignDetails +proparray2 = WbemInst.AssignTypes + +onemore = ubound(proparray1) + 1 +redim preserve proparray1( onemore ) 'add one to size of array +redim preserve proparray2( onemore ) +proparray1( onemore ) = strSubnet +proparray2( onemore ) = "IP Subnet" +WbemInst.AssignDetails = proparray1 +WbemInst.AssignTypes = proparray2 +WbemInst.Put_ , WbemContext +objSMS.ExecMethod "SMS_SiteControlFile.Filetype=0,SiteCode=""" & _ + strSMSSiteCode & """", "Commit", , , WbemContext +objSMS.Get("SMS_SiteControlFile").ReleaseSessionHandle _ + WbemContext.Item("SessionHandle").Value diff --git a/Chapter02/2-3_ComputeIPSubnet.vbs b/Chapter02/2-3_ComputeIPSubnet.vbs new file mode 100644 index 0000000..ce6f839 --- /dev/null +++ b/Chapter02/2-3_ComputeIPSubnet.vbs @@ -0,0 +1,35 @@ +'adopted from the SMS 2003 Scenarios and Procedures guide +strIPAddress = inputbox("Enter IP Address") +strSubnetMask = inputbox("Enter Subnet Mask") + +dim addressbytes(4) +dim subnetmaskbytes(4) +i=0 +period = 1 +while period<>len( strIPAddress ) + 2 + prevperiod=period + period = instr( period+1, strIPAddress, "." ) + 1 + if period = 1 then period = len( strIPAddress ) + 2 + addressbyte = _ + mid( strIPAddress, prevperiod, period-prevperiod-1 ) + addressbytes(i)=addressbyte + i=i+1 +wend + +i=0 +period = 1 +while period<>len( strSubnetMask ) + 2 + prevperiod=period + period = instr( period+1, strSubnetMask, "." ) + 1 + if period = 1 then period = len( strSubnetMask ) + 2 + subnetmaskbyte = _ + mid( strSubnetMask, prevperiod, period-prevperiod-1 ) + subnetmaskbytes(i)=subnetmaskbyte + i=i+1 +wend +for i=0 to 3 + subnet = subnet & _ + (addressbytes(i) AND subnetmaskbytes(i)) & "." +next +subnet = left( subnet, len(subnet)-1 ) +msgbox "Subnet: " & subnet diff --git a/Chapter02/2-4_AddADSiteBoundary.vbs b/Chapter02/2-4_AddADSiteBoundary.vbs new file mode 100644 index 0000000..6739b57 --- /dev/null +++ b/Chapter02/2-4_AddADSiteBoundary.vbs @@ -0,0 +1,40 @@ +strSMSServer = +strADSite = "Cleveland" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.SiteCode + end if +Next + +Set WbemContext=CreateObject("WbemScripting.SWbemNamedValueSet") +WbemContext.Add "SessionHandle", objSMS.ExecMethod _ + ("SMS_SiteControlFile", "GetSessionHandle").SessionHandle +objSMS.ExecMethod "SMS_SiteControlFile.Filetype=1,SiteCode='" _ + & strSMSSiteCode & "'", "Refresh", , , WbemContext +'retrieve boundary details +Set WbemInst = objSMS.Get _ + ("SMS_SCI_SiteAssignment.Filetype=2,Itemtype='Site Assignment'," _ + & "SiteCode='" & strSMSSiteCode & _ + "',ItemName='Site Assignment'", , WbemContext) +proparray1 = WbemInst.AssignDetails +proparray2 = WbemInst.AssignTypes + +onemore = ubound(proparray1) + 1 +redim preserve proparray1( onemore ) 'add one to size of array +redim preserve proparray2( onemore ) +proparray1( onemore ) = strADSite +proparray2( onemore ) = "Active Directory site" +WbemInst.AssignDetails = proparray1 +WbemInst.AssignTypes = proparray2 +WbemInst.Put_ , WbemContext +objSMS.ExecMethod "SMS_SiteControlFile.Filetype=0,SiteCode=""" & _ + strSMSSiteCode & """", "Commit", , , WbemContext +objSMS.Get("SMS_SiteControlFile").ReleaseSessionHandle _ + WbemContext.Item("SessionHandle").Value diff --git a/Chapter02/2-5_AddSiteBoundaries.vbs b/Chapter02/2-5_AddSiteBoundaries.vbs new file mode 100644 index 0000000..2f7feb2 --- /dev/null +++ b/Chapter02/2-5_AddSiteBoundaries.vbs @@ -0,0 +1,78 @@ +Set objArgs = WScript.Arguments +strSMSServer = objArgs(0) +strSiteToConfig= objArgs(1) +strBoundaryType = ucase(objArgs(2)) +strBoundaryData = objArgs(3) +'creating 2 arrays of size one +Dim inputArray1(1) +Dim inputArray2(1) + +select case strBoundaryType + case "SUBNET" + strBoundaryType = "IP Subnet" + case "AD" + strBoundaryType = "Active Directory site" +End Select + +inputArray1(0) = trim(strBoundaryData) +inputArray2(0) = trim(strBoundaryType) + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSWbemServices = objLoc.ConnectServer _ + (Loc.Machine, "root\sms\site_" & Loc.SiteCode) + end if +Next + + +Set objSWbemContext=CreateObject _ + ("WbemScripting.SWbemNamedValueSet") +objSWbemContext.Add "SessionHandle", _ + objSWbemServices.ExecMethod("SMS_SiteControlFile", _ + "GetSessionHandle").SessionHandle +objSWbemServices.ExecMethod _ + "SMS_SiteControlFile.Filetype=1,Sitecode='" & _ + strSiteToConfig & "'", "RefreshSCF", , , objSWbemContext +Set objSWbemInst = objSWbemServices.Get _ + ("SMS_SCI_SiteAssignment.Filetype=2,Itemtype='" & _ + "Site Assignment',Sitecode='" & strSiteToConfig & _ + "',ItemName='Site Assignment'", , objSWbemContext) + +'Retrieve the boundary details. +proparray1 = objSWbemInst.AssignDetails +proparray2 = objSWbemInst.AssignTypes + +if ubound(objSWbemInst.AssignDetails)=-1 then + 'There are no boundaries so create an array. + bounds=0 + redim proparray1(0) + redim proparray2(0) + proparray1(bounds)=inputArray1(0) + proparray2(bounds)=inputArray2(0) +Else + bounds=ubound (objSWbemInst.AssignDetails)+1 + 'Increase array for new boundaries + ReDim Preserve proparray1 (ubound (proparray1) + _ + ubound (inputArray1)) + ReDim Preserve proparray2 (ubound (proparray2) + _ + ubound (inputArray2)) + for i= 0 to ubound(inputArray1)-1 'Add boundaries + proparray1(bounds+i)=inputArray1(i) + proparray2(bounds+i)=inputArray2(i) + Next +End If + +objSWbemInst.AssignDetails = proparray1 +objSWbemInst.AssignTypes = proparray2 +objSWbemInst.Put_ , objSWbemContext + +objSWbemServices.ExecMethod _ + "SMS_SiteControlFile.Filetype=0,Sitecode=""" & _ + strSiteToConfig & """", "Commit", , , objSWbemContext +objSWbemServices.Get("SMS_SiteControlFile"). _ + ReleaseSessionHandle objSWbemContext.Item _ + ("SessionHandle").Value diff --git a/Chapter02/2-6_ShowRoamingSiteBoundaries.vbs b/Chapter02/2-6_ShowRoamingSiteBoundaries.vbs new file mode 100644 index 0000000..7f11330 --- /dev/null +++ b/Chapter02/2-6_ShowRoamingSiteBoundaries.vbs @@ -0,0 +1,40 @@ +Set objArgs = WScript.Arguments +strSMSServer = objArgs(0) +strSiteToDisplay = ucase(objArgs(1)) + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +strInfo = "Roaming Site Boundary Informaiton for Site " & _ + strSiteToDisplay & vbCRLF + +Set boundaries=objSMS.Get("SMS_SCI_RoamingBoundary." & _ + "SiteCode='" & strSiteToDisplay & "',Filetype=2,ItemName='" & _ + "Roaming Boundary',ItemType='Roaming Boundary'") +if boundaries.IncludeSiteBoundary then + strInfo = strInfo & "Site Boundaries are included in the "& _ + "local roaming boundaries." & vbCRLF +else + strInfo = strInfo & "Site Boundaries are NOT included in the "& _ + "local roaming boundaries." & vbCRLF +end if +msgbox ubound(boundaries.Details) +For i=0 to ubound(boundaries.Details) + if boundaries.Flags(i) = 1 then + strBoundary = "Remote Boundary" + else + strBoundary = "Local Boundary" + end if + strInfo = strInfo & _ + boundaries.Types(i) & _ + ": " & boundaries.Details(i) & vbTAB & strBoundary & vbCRLF +Next +wscript.echo strInfo diff --git a/Chapter02/2-7_AddRoamingSiteBoundaries.vbs b/Chapter02/2-7_AddRoamingSiteBoundaries.vbs new file mode 100644 index 0000000..53c4f91 --- /dev/null +++ b/Chapter02/2-7_AddRoamingSiteBoundaries.vbs @@ -0,0 +1,95 @@ +Set objArgs = WScript.Arguments +strSMSServer = objArgs(0) +strSiteToModify = objArgs(1) +strBoundaryType = ucase(objArgs(2)) +strBoundaryData = objArgs(3) +strRemote = ucase(objArgs(4)) +Dim inputArray1(1) +Dim inputArray2(1) +Dim inputArray3(1) + +select case strBoundaryType + case "SUBNET" + strBoundaryType = "IP Subnets" + case "AD" + strBoundaryType = "AD Site Name" + case "RANGE" + strBoundaryType = "IP Ranges" +End Select + +select case strRemote + case "LOCAL" + strRemote = 0 + case "REMOTE" + strRemote = 1 +end select +inputArray1(0)=strBoundaryData +inputArray2(0)=strRemote +inputArray3(0)=strBoundaryType + + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set objSWbemContext = CreateObject _ + ("WbemScripting.SWbemNamedValueSet") +objSWbemContext.Add "SessionHandle", _ + objSMS.ExecMethod("SMS_SiteControlFile", _ + "GetSessionHandle").SessionHandle +objSMS.ExecMethod _ + "SMS_SiteControlFile.Filetype=1,Sitecode='" & _ + strSiteToModify & "'", "RefreshSCF", , , objSWbemContext +Set objSWbemInst = objSMS.Get _ + ("SMS_SCI_RoamingBoundary.Filetype=2,Itemtype='" & _ + "Roaming Boundary',Sitecode='" & strSiteToModify & _ + "',ItemName='Roaming Boundary'", , objSWbemContext) + +'Retrieve the roaming boundary details. +proparray1 = objSWbemInst.Details +proparray2 = objSWbemInst.Flags +proparray3 = objSWbemInst.Types + +if ubound(objSWbemInst.Details)=-1 then + 'There are no boundaries so create an array. + bounds=0 + redim proparray1(0) + redim proparray2(0) + redim proparray3(0) + proparray1(bounds)=inputArray1(0) + proparray2(bounds)=inputArray2(0) + proparray3(bounds)=inputArray3(0) +Else + bounds=ubound (objSWbemInst.Details)+1 + 'Increase array for new boundaries + ReDim Preserve proparray1 (ubound (proparray1) + _ + ubound (inputArray1)) + ReDim Preserve proparray2 (ubound (proparray2) + _ + ubound (inputArray2)) + ReDim Preserve proparray3 (ubound (proparray3) + _ + ubound (inputArray3)) + for i= 0 to ubound(inputArray1)-1 'Add boundaries + proparray1(bounds+i)=inputArray1(i) + proparray2(bounds+i)=inputArray2(i) + proparray3(bounds+i)=inputArray3(i) + Next +End If + +objSWbemInst.Details = proparray1 +objSWbemInst.Flags = proparray2 +objSWbemInst.Types = proparray3 +objSWbemInst.Put_ , objSWbemContext + +objSMS.ExecMethod _ + "SMS_SiteControlFile.Filetype=0,Sitecode=""" & _ + strSiteToModify & """", "Commit", , , objSWbemContext +objSMS.Get("SMS_SiteControlFile"). _ + ReleaseSessionHandle objSWbemContext.Item _ + ("SessionHandle").Value diff --git a/Chapter03/3-10_SetUpdateCollInterval.vbs b/Chapter03/3-10_SetUpdateCollInterval.vbs new file mode 100644 index 0000000..8bde7fa --- /dev/null +++ b/Chapter03/3-10_SetUpdateCollInterval.vbs @@ -0,0 +1,24 @@ +strSMSServer = +strCollID = "LAB0002B" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set Token = objSMS.Get("SMS_ST_RecurInterval") +Token.DaySpan = 1 +Token.StartTime = "20051202103000.000000+***" 'wmi date-string +'If omitted, StartTime = Jan 1, 1990 - this shouldn't +'cause any issues +Set objCollection = objSMS.Get _ + ("SMS_Collection.CollectionID='" & strCollID & "'") +objCollection.RefreshSchedule = Array(Token) +objCollection.RefreshType = 2 'Periodic refresh +objCollection.Put_ diff --git a/Chapter03/3-11_ConvertToWMIDate.vbs b/Chapter03/3-11_ConvertToWMIDate.vbs new file mode 100644 index 0000000..460979d --- /dev/null +++ b/Chapter03/3-11_ConvertToWMIDate.vbs @@ -0,0 +1,14 @@ +Function ConvertToWMIDate(strDate) + strYear = year(strDate) + strMonth = month(strDate) + strDay = day(strDate) + strHour = hour(strDate) + strMinute = minute(strDate) + 'pad date appropriately + if len(strmonth) = 1 then strMonth = "0" & strMonth + if len(strDay) = 1 then strDay = "0" & strDay + if len(strHour) = 1 then strHour = "0" & strHour + if len(strMinute) = 1 then strMinute = "0" & strMinute + ConvertToWMIDate = strYear & strMonth & strDay & strHour & _ + strMinute & "00.000000+***" +end function diff --git a/Chapter03/3-12_LimitCollectionMembership.vbs b/Chapter03/3-12_LimitCollectionMembership.vbs new file mode 100644 index 0000000..302625b --- /dev/null +++ b/Chapter03/3-12_LimitCollectionMembership.vbs @@ -0,0 +1,26 @@ +strSMSServer = + +strCollID = "LAB0002B" 'this is the collection to modify +strCollLimit = "SMS000GS" 'this is the limiting collection + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set objCollection=objSMS.Get("SMS_Collection='" & _ + strCollID & "'" ) +'Get the array of embedded SMS_CollectionRule objects. +RuleSet = objCollection.CollectionRules +For Each Rule In RuleSet + if Rule.Path_.Class = "SMS_CollectionRuleQuery" then + Rule.LimitToCollectionID = strCollLimit + end if +Next +objCollection.Put_ diff --git a/Chapter03/3-13_DelDirectMemberShip.vbs b/Chapter03/3-13_DelDirectMemberShip.vbs new file mode 100644 index 0000000..f77c905 --- /dev/null +++ b/Chapter03/3-13_DelDirectMemberShip.vbs @@ -0,0 +1,23 @@ +strSMSServer = + +strCollID = "LAB0002B" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set objCollection=objSMS.Get("SMS_Collection='" & strCollID & "'" ) +'Get the array of embedded SMS_CollectionRule objects. +RuleSet = objCollection.CollectionRules +For Each Rule In RuleSet + if Rule.Path_.Class = "SMS_CollectionRuleDirect" then + objCollection.DeleteMembershipRule Rule + end if +Next diff --git a/Chapter03/3-14_DelResource.vbs b/Chapter03/3-14_DelResource.vbs new file mode 100644 index 0000000..bd0d920 --- /dev/null +++ b/Chapter03/3-14_DelResource.vbs @@ -0,0 +1,34 @@ +strSMSServer = + +strComputer = "Computer1" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.SiteCode + end if +Next + +'get the resource ID of the computer +intResourceID = GetResourceID(strComputer) + +'Remove ResourceID +Set objResource = GetObject( "WinMgmts:\\" & strSMSServer & _ + "\root\SMS\site_" & strSMSSiteCode & _ + ":SMS_R_System.ResourceID=" & cint(intResourceID)) +objResource.Delete_ +wscript.echo "Deleted " & strComputer & "(" & intResourceID & ")" + +Function GetResourceID(strComputerName) + Set colResourceIDs = objSMS.ExecQuery _ + ("select ResourceID from SMS_R_System where Name = '" & _ + strComputer & "'") + for each objResID in colResourceIDs + GetResourceID = objResID.ResourceID + next +End Function diff --git a/Chapter03/3-15_ModCollPerms.vbs b/Chapter03/3-15_ModCollPerms.vbs new file mode 100644 index 0000000..aae0af4 --- /dev/null +++ b/Chapter03/3-15_ModCollPerms.vbs @@ -0,0 +1,22 @@ +strSMSServer = +strHelpDesk="LAB\SMSHelpDesk" 'Domain\Group or username +strCollID = "LAB00159" 'ID of the collection + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set objNewRight = objSMS.Get _ + ("SMS_UserInstancePermissions").SpawnInstance_() +objNewRight.UserName = strHelpDesk +objNewRight.ObjectKey = 1 '1=collection +objNewRight.InstanceKey = strCollID +objNewRight.InstancePermissions = 1+2'grant Read and Modify +objNewRight.Put_ diff --git a/Chapter03/3-16_ListAdvertToColl.vbs b/Chapter03/3-16_ListAdvertToColl.vbs new file mode 100644 index 0000000..d865763 --- /dev/null +++ b/Chapter03/3-16_ListAdvertToColl.vbs @@ -0,0 +1,60 @@ +strSMSServer = +strCollID = "LAB000FE" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +ListAdverts strCollID, False +CheckParent strCollID + +Sub ListAdverts(strCollID,blnSubCollect) + If blnSubCollect then + 'This is to check all parent questions of the + 'collection in question. We can only look at + 'parent collections that are set to "Include + 'members of subcollections" + Set colAdverts = objSMS.ExecQuery _ + ("select * from SMS_Advertisement where " & _ + "CollectionID = '" & strCollID & "' and " & _ + "IncludeSubCollection = 1") + Else + 'This is for the first check, this will look for + 'advertisements assigned directly to the collection + Set colAdverts = objSMS.ExecQuery _ + ("select * from SMS_Advertisement where " & _ + "CollectionID = '" & strCollID & "'") + end if + for each objAdvert in colAdverts + wscript.echo "Advertisement: " & _ + objAdvert.AdvertisementName + wscript.echo " Collection: " & _ + GetCollectionName(objAdvert.CollectionID) & _ + " (" & objAdvert.CollectionID & ")" & VbCRLF + next +End Sub + +Function GetCollectionName(strCollID) + Set instColl = objSMS.Get _ + ("SMS_Collection.CollectionID=""" & strCollID & """") + GetCollectionName = instColl.Name +End Function + +Sub CheckParent(strCollID) + Set colParents = objSMS.ExecQuery _ + ("select * from SMS_CollectToSubCollect where subCollectionID = '" & _ + strCollID & "'") + for each objParent in colParents + if not objParent.ParentCollectionID = "COLLROOT" then + ListAdverts objParent.ParentCollectionID , True + CheckParent objParent.ParentCollectionID + end if + next +End Sub diff --git a/Chapter03/3-17_ViewAssignedAdvertsToMachine.vbs b/Chapter03/3-17_ViewAssignedAdvertsToMachine.vbs new file mode 100644 index 0000000..0c35255 --- /dev/null +++ b/Chapter03/3-17_ViewAssignedAdvertsToMachine.vbs @@ -0,0 +1,55 @@ +strSMSServer = + +strComputer = "Computer1" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +'first, get the resource ID of the computer +intResourceID = GetResourceID(strComputer) + +Set colAdverts = objSMS.ExecQuery _ +("select * from SMS_ClientAdvertisementStatus where ResourceID = " & _ + intResourceID) +for each strAdvert in colAdverts 'enumerate all adverts for client + wscript.echo GetAdvertisementName(strAdvert.AdvertisementID) & _ + "(" & strAdvert.AdvertisementID & ")" & vbTAB & _ + strAdvert.LastStateName & vbTAB & strAdvert.LastStatusTime & _ + vbTAB & GetCollectionName(strAdvert.AdvertisementID) +next + +'used to obtain the Advertisement Name +Function GetAdvertisementName(strAdvertID) + Set instAdvert = objSMS.Get _ + ("SMS_Advertisement.AdvertisementID='" & strAdvertID & "'") + GetAdvertisementName = instAdvert.AdvertisementName +End Function + +'used to obtain the Collection Name +Function GetCollectionName(strAdvertID) + 'first, get advert based on advert ID + Set instAdvert = objSMS.Get _ + ("SMS_Advertisement.AdvertisementID='" & strAdvertID & "'") + 'then, get collection name based on collectionID from advert + Set instCollection = objSMS.Get _ + ("SMS_Collection.CollectionID='" & instAdvert.CollectionID & "'") + GetCollectionName = instCollection.Name +End Function + +'used to obtain the SMS resource ID +Function GetResourceID(strComputerName) + Set colResourceIDs = objSMS.ExecQuery _ + ("select ResourceID from SMS_R_System where Name = '" & _ + strComputer & "'") + for each objResID in colResourceIDs + GetResourceID = objResID.ResourceID + next +End Function diff --git a/Chapter03/3-1_CreateCollection.vbs b/Chapter03/3-1_CreateCollection.vbs new file mode 100644 index 0000000..6aeb9ae --- /dev/null +++ b/Chapter03/3-1_CreateCollection.vbs @@ -0,0 +1,39 @@ +strSMSServer = +strParentCollID = "COLLROOT" 'This creates the collection in +'the collection root. Replace COLLROOT with the CollectionID +'of an existing collection to make the new collection a child + +strCollectionName = "Systems Without Windows Update Agent" +strCollectionComment = "This collection contains all systems " & _ + "that do not have the Windows Update Agent installed." + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set newCollection = objSMS.Get("SMS_Collection").SpawnInstance_() + +newCollection.Name = strCollectionName +newCollection.OwnedByThisSite = True +newCollection.Comment = strCollectionComment +path=newCollection.Put_ + +'the following two lines are used to obtain the CollectionID +'of the collection we just created +Set Collection=objSMS.Get(path) +strCollID= Collection.CollectionID +'now we create a relationship betwen the new collection +'and it's parent. + +Set newCollectionRelation = objSMS.Get _ + ( "SMS_CollectToSubCollect" ).SpawnInstance_() +newCollectionRelation.parentCollectionID = strParentCollID +newCollectionRelation.subCollectionID = strCollID +newCollectionRelation.Put_ diff --git a/Chapter03/3-2_ListSubCollections.vbs b/Chapter03/3-2_ListSubCollections.vbs new file mode 100644 index 0000000..cb32f9f --- /dev/null +++ b/Chapter03/3-2_ListSubCollections.vbs @@ -0,0 +1,44 @@ +strSMSServer = + +'If you want to start from the root collection, set +' strCollID = "COLLROOT" +strCollID = "LAB00080" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +wscript.echo strCollID & vbTAB & GetCollectionName(strCollID) + +DisplaySubCollections strCollID, 3 + +Sub DisplaySubCollections(strCollID, intSpace) + +strWQL ="SELECT col.* FROM SMS_Collection as col " & _ + "INNER JOIN SMS_CollectToSubCollect as ctsc " & _ + "ON col.CollectionID = ctsc.subCollectionID " & _ + "WHERE ctsc.parentCollectionID='" & strcollID & "' " & _ + "ORDER by col.Name" + + Set colSubCollections = objSMS.ExecQuery(strWQL) + + For each objSubCollection in colSubCollections + wscript.echo space(intSpace) & objSubCollection.CollectionID & _ + vbTAB & objSubCollection.Name + + DisplaySubCollections strSubCollID, intSpace + 3 + Next +End Sub + +Function GetCollectionName(strCollID) + Set objCollection = objSMS.Get _ + ("SMS_Collection.CollectionID='" & strCollID & "'") + GetCollectionName = objCollection.Name +End Function diff --git a/Chapter03/3-3_ListCollectionIDs.vbs b/Chapter03/3-3_ListCollectionIDs.vbs new file mode 100644 index 0000000..fec1a22 --- /dev/null +++ b/Chapter03/3-3_ListCollectionIDs.vbs @@ -0,0 +1,19 @@ +strSMSServer = + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set colCollections = objSMS.ExecQuery _ +("select * from SMS_Collection order by Name") +for each objCollection in colCollections + wscript.echo objCollection.Name & vbTAB & _ + objCollection.CollectionID +next diff --git a/Chapter03/3-4_DeleteCollection.vbs b/Chapter03/3-4_DeleteCollection.vbs new file mode 100644 index 0000000..9dfdfb8 --- /dev/null +++ b/Chapter03/3-4_DeleteCollection.vbs @@ -0,0 +1,18 @@ +strSMSServer = + +strCollID = "LAB001A7" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + + Set col = objSMS.Get _ + ("SMS_Collection.CollectionID='" & strCollID & "'") +Col.Delete_ diff --git a/Chapter03/3-5_CreateCollectionLink.vbs b/Chapter03/3-5_CreateCollectionLink.vbs new file mode 100644 index 0000000..737a8f3 --- /dev/null +++ b/Chapter03/3-5_CreateCollectionLink.vbs @@ -0,0 +1,31 @@ +strSMSServer = + +strParentColl = "LAB0000D" 'parent collection ID +strSubColl = "LAB0000E" 'collection ID to link + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set ColSvcs = objSMS.Get("SMS_Collection") + ColSvcs.VerifyNoLoops "SMS_Collection.CollectionID=""" & _ + strParentColl & """", "SMS_Collection.CollectionID=""" & _ + strSubColl & """", Result + +if Result = 0 then + wscript.echo "Link would cause looping condition, exiting" +else + Set objCol = objSMS.Get _ + ("SMS_CollectToSubCollect").SpawnInstance_() + objCol.parentCollectionID = strParentColl + objCol.subCollectionID = strSubColl + objCol.Put_ + wscript.echo "Created Collection Link!" +end if \ No newline at end of file diff --git a/Chapter03/3-6_CreateDirectMembershipRule.vbs b/Chapter03/3-6_CreateDirectMembershipRule.vbs new file mode 100644 index 0000000..5ffaaae --- /dev/null +++ b/Chapter03/3-6_CreateDirectMembershipRule.vbs @@ -0,0 +1,32 @@ +strSMSServer = + +strCollID = "LAB0000F" 'ID of the collection +strComputerName = "2kPro" 'computer name to add + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +'obtain the ResourceID for strComputerName +Set colResourceIDs=objSMS.ExecQuery _ + ("SELECT ResourceId FROM SMS_R_System WHERE NetbiosName ='" & _ + strComputerName & "'") +For each insResource in colResourceIDs + strNewResourceID = insResource.ResourceID +Next +'add the ResourceID to the collection +Set instColl = objSMS.Get _ + ("SMS_Collection.CollectionID=""" & strCollID & """") +Set instDirectRule = objSMS.Get _ + ("SMS_CollectionRuleDirect").SpawnInstance_ () +instDirectRule.ResourceClassName = "SMS_R_System" +instDirectRule.ResourceID = strNewResourceID +instDirectRule.RuleName = strComputerName +instColl.AddMembershipRule instDirectRule diff --git a/Chapter03/3-7_CreateQueryMembershipRule.vbs b/Chapter03/3-7_CreateQueryMembershipRule.vbs new file mode 100644 index 0000000..b886cbb --- /dev/null +++ b/Chapter03/3-7_CreateQueryMembershipRule.vbs @@ -0,0 +1,35 @@ +strSMSServer = + +strCollID = "LAB0000F" +strQuery = "select * from SMS_R_System inner join " & _ + "SMS_G_System_ADD_REMOVE_PROGRAMS on " & _ + "SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID = " & _ + "SMS_R_System.ResourceId where " & _ + "SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName = 'SMS View'" +strQueryName = "Systems that have SMSView Installed" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + + Set instCollection = objSMS.Get _ + ("SMS_Collection.CollectionID='" & strCollID & "'") +Set clsQueryRule = objSMS.Get _ + ("SMS_CollectionRuleQuery") + +'next we need to validate the query +ValidQuery = clsQueryRule.ValidateQuery(strQuery) + +If ValidQuery Then + Set instQueryRule = clsQueryRule.SpawnInstance_ + instQueryRule.QueryExpression = strQuery + instQueryRule.RuleName = strQueryName + instCollection.AddMembershipRule instQueryRule +End If diff --git a/Chapter03/3-8_CreateSubSelectQueryRule.vbs b/Chapter03/3-8_CreateSubSelectQueryRule.vbs new file mode 100644 index 0000000..8a76706 --- /dev/null +++ b/Chapter03/3-8_CreateSubSelectQueryRule.vbs @@ -0,0 +1,47 @@ +strSMSServer = + +strCollID = "LAB0002B" + +strQuery = "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 inner join " & _ + "SMS_G_System_SYSTEM on " &_ + "SMS_G_System_SYSTEM.ResourceID = " & _ + "SMS_R_System.ResourceId where " & _ + "SMS_G_System_SYSTEM.Name not in (select " & _ + "SMS_G_System_SYSTEM.Name from SMS_R_System inner " & _ + "join SMS_G_System_SoftwareFile on " & _ + "SMS_G_System_SoftwareFile.ResourceID = " & _ + "SMS_R_System.ResourceId inner join " & _ + "SMS_G_System_SYSTEM on " & _ + "SMS_G_System_SYSTEM.ResourceID =" & _ + "SMS_R_System.ResourceId where " & _ + "SMS_G_System_SoftwareFile.FileName = 'wuauclt.exe' " & _ + "and SMS_G_System_SoftwareFile.FilePath like '%system32\\%')" +strQueryName = "Systems That Need Windows Update Agent" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set instCollection = objSMS.Get _ + ("SMS_Collection.CollectionID='" & strCollID & "'") +Set clsQueryRule = objSMS.Get _ + ("SMS_CollectionRuleQuery") +'make sure we have a valid query +ValidQuery = clsQueryRule.ValidateQuery(strQuery) +If ValidQuery Then + Set instQueryRule = clsQueryRule.SpawnInstance_ + instQueryRule.QueryExpression = strQuery + instQueryRule.RuleName = strQueryName + instCollection.AddMembershipRule instQueryRule +End If diff --git a/Chapter03/3-9_UpdateCollMembership.vbs b/Chapter03/3-9_UpdateCollMembership.vbs new file mode 100644 index 0000000..5a12311 --- /dev/null +++ b/Chapter03/3-9_UpdateCollMembership.vbs @@ -0,0 +1,19 @@ +strSMSServer = + +strCollID = "LAB00017" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objCollection = GetObject( "WinMgmts:!\\" & strSMSServer & _ + "\root\SMS\site_" & strSMSSiteCode & _ + ":SMS_Collection.CollectionID='" & strCollID & "'") +objCollection.RequestRefresh False diff --git a/Chapter04/4-10_LoadDPs_OneSite.vbs b/Chapter04/4-10_LoadDPs_OneSite.vbs new file mode 100644 index 0000000..a2d8677 --- /dev/null +++ b/Chapter04/4-10_LoadDPs_OneSite.vbs @@ -0,0 +1,32 @@ +strSMSServer = + +strSiteCode = "BLO" 'this is the site code of the DP to add +PackageID = "LAB0000A" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set AllDPs = objSMS.ExecQuery _ + ("Select * From SMS_SystemResourceList WHERE " & _ + "RoleName='SMS Distribution Point' and " & _ + "SiteCode='" & strSiteCode & "'") +For Each DP In AllDPs + Wscript.echo DP.SiteCode & vbTAB & DP.ServerName + Set Site = objSMS.Get("SMS_Site='" & DP.SiteCode & "'") + Set newDP = objSMS.Get _ + ("SMS_DistributionPoint").SpawnInstance_() + newDP.ServerNALPath = DP.NALPath + newDP.PackageID = PackageID + newDP.SiteCode = DP.SiteCode + newDP.SiteName = Site.SiteName + newDP.Put_ +Next diff --git a/Chapter04/4-11_LoadDPs_All.vbs b/Chapter04/4-11_LoadDPs_All.vbs new file mode 100644 index 0000000..919ec4a --- /dev/null +++ b/Chapter04/4-11_LoadDPs_All.vbs @@ -0,0 +1,30 @@ +strSMSServer = + +PackageID = "LAB0000A" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set AllDPs = objSMS.ExecQuery _ + ("Select * From SMS_SystemResourceList WHERE " & _ + "RoleName='SMS Distribution Point'") +For Each DP In AllDPs + Wscript.echo DP.SiteCode & vbTAB & DP.ServerName + Set Site = objSMS.Get("SMS_Site='" & DP.SiteCode & "'") + Set newDP = objSMS.Get _ + ("SMS_DistributionPoint").SpawnInstance_() + newDP.ServerNALPath = DP.NALPath + newDP.PackageID = PackageID + newDP.SiteCode = DP.SiteCode + newDP.SiteName = Site.SiteName + newDP.Put_ +Next diff --git a/Chapter04/4-12_RemoveFromDPs_OneSite.vbs b/Chapter04/4-12_RemoveFromDPs_OneSite.vbs new file mode 100644 index 0000000..407a513 --- /dev/null +++ b/Chapter04/4-12_RemoveFromDPs_OneSite.vbs @@ -0,0 +1,26 @@ +strSMSServer = + +strSiteCode="BLO" +strPackageID = "LAB0000A" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set AllDPs = objSMS.ExecQuery _ + ("Select * From SMS_DistributionPoint where " & _ + "PackageID = '" & strPackageID & "'") +for each DP in AllDPs + if DP.SiteCode = strSiteCode then + wscript.echo DP.ServerNALPath + DP.Delete_ + end if +next diff --git a/Chapter04/4-13_RemoveFromAllDPs.vbs b/Chapter04/4-13_RemoveFromAllDPs.vbs new file mode 100644 index 0000000..803369c --- /dev/null +++ b/Chapter04/4-13_RemoveFromAllDPs.vbs @@ -0,0 +1,23 @@ +strSMSServer = + +strPackageID = "LAB0000A" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set AllDPs = objSMS.ExecQuery _ + ("Select * From SMS_DistributionPoint where " & _ + "PackageID = '" & strPackageID & "'") +for each DP in AllDPs + wscript.echo "Removing " & DP.ServerNALPath + DP.Delete_ +next diff --git a/Chapter04/4-14_UnloadOneDP.vbs b/Chapter04/4-14_UnloadOneDP.vbs new file mode 100644 index 0000000..05c2388 --- /dev/null +++ b/Chapter04/4-14_UnloadOneDP.vbs @@ -0,0 +1,31 @@ +strSMSServer = 'primary site server + +strSMSSiteCodeforDP = 'site code that + ' contains packages to remove +strServerSharePath = "\\sms-testgmr\smspkgd$" + 'DP path + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objDPs = objSMS.ExecQuery("select * from " & _ + "SMS_DistributionPoint where SiteCode = '" & _ + strSMSSiteCodeforDP & "'") + +For each objDP in objDPs + if instr(ucase(objDP.ServerNALPath), _ + ucase(strServerSharePath)) then + wscript.echo "Removing " & objDP.PackageID & _ + vbTAB & objDP.ServerNALPath + objDP.Delete_ + end if +Next diff --git a/Chapter04/4-15_UpdateDPs.vbs b/Chapter04/4-15_UpdateDPs.vbs new file mode 100644 index 0000000..ab6f73e --- /dev/null +++ b/Chapter04/4-15_UpdateDPs.vbs @@ -0,0 +1,18 @@ +strSMSServer = "SMSVPC" +strPackageID = "LAB000BD" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.SiteCode + end if +Next + +Set objPkg = objSMS.Get _ + ("SMS_Package.PackageID=""" & strPackageID & """") +objPkg.RefreshPkgSource(0) diff --git a/Chapter04/4-16_RefreshDPs.vbs b/Chapter04/4-16_RefreshDPs.vbs new file mode 100644 index 0000000..edd1a92 --- /dev/null +++ b/Chapter04/4-16_RefreshDPs.vbs @@ -0,0 +1,25 @@ +strSMSServer = + +strPackageID = "LAB0000A" +StrSiteCode = "CLE" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.SiteCode + end if +Next + +Set DPs = objSMS.ExecQuery _ + ("Select * From SMS_DistributionPoint " & _ + "WHERE SiteCode='" & strSiteCode & _ + "' AND PackageID='" & strPackageID & "'") +For Each DP In DPs + DP.RefreshNow = True + DP.Put_ +Next diff --git a/Chapter04/4-17_CreatePackageFolder.vbs b/Chapter04/4-17_CreatePackageFolder.vbs new file mode 100644 index 0000000..ace165e --- /dev/null +++ b/Chapter04/4-17_CreatePackageFolder.vbs @@ -0,0 +1,22 @@ +strSMSServer = + +strNewFolderName = "Security Patches" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.SiteCode + end if +Next + +Set newFolder = objSMS.Get("SMS_ObjectContainerNode") _ + .SpawnInstance_() +newFolder.Name = strNewFolderName +newFolder.ObjectType = 2 'package +newFolder.ParentContainerNodeId = 0 +newFolder.Put_ diff --git a/Chapter04/4-18_MovePackagesBtwnFolder.vbs b/Chapter04/4-18_MovePackagesBtwnFolder.vbs new file mode 100644 index 0000000..dadbce2 --- /dev/null +++ b/Chapter04/4-18_MovePackagesBtwnFolder.vbs @@ -0,0 +1,14 @@ +strSMSServer = +strSMSSiteCode = +strPackageIDs = "LAB00004,LAB00001" +'to move more than one, separate with commas +intSourceFolder=0 'Source Folder (root node in this case) +intDestFolder=4 'Destination Folder +intObjectType=2 '2=Package for type of object +Set loc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS = loc.ConnectServer(SMSServer, "root\SMS\site_" & _ + SMSSiteCode) +Set objFolder = objSMS.Get("SMS_ObjectContainerItem") +arrPackageIDs = split(strPackageIDs, ",") +retval = objFolder.MoveMembers _ + (arrPackageIDs, intSourceFolder , intDestFolder , intObjectType) diff --git a/Chapter04/4-1_CreatePackage.vbs b/Chapter04/4-1_CreatePackage.vbs new file mode 100644 index 0000000..7ada214 --- /dev/null +++ b/Chapter04/4-1_CreatePackage.vbs @@ -0,0 +1,35 @@ +strSMSServer = + +'Specify package attributes one time. From here on out +'we reference these variables. +pkgName = "Visual Studio .NET Framework 1.1 SP1" +pkgSource = "\\smsvpc\source\KB867460" +pkgDesc = "This Package Installs .NET 1.1 SP1" +pkgManufacturer = "Microsoft" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +'Define package attributes such as name, source for the files, etc. +Set newPackage = objSMS.Get("SMS_Package").SpawnInstance_() +newPackage.Name = pkgName +newPackage.Description = pkgDesc +newPackage.Manufacturer = pkgManufacturer +newPackage.PkgSourceFlag = 2 +'2=direct, 1=no source 3=use compressed source +newPackage.PkgSourcePath = pkgSource +path=newPackage.Put_ + +'the following three lines are used to obtain the PackageID +'of the package we just created +Set Package=objSMS.Get(path) +PackageID= Package.PackageID +wscript.echo PackageID & " = " & pkgName diff --git a/Chapter04/4-2_ShowPackageIDs.vbs b/Chapter04/4-2_ShowPackageIDs.vbs new file mode 100644 index 0000000..a06e5fe --- /dev/null +++ b/Chapter04/4-2_ShowPackageIDs.vbs @@ -0,0 +1,18 @@ +strSMSServer = + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set Packages = objSMS.ExecQuery _ + ("Select * From SMS_Package order by Name") +For each objPackage in Packages + wscript.echo objPackage.Name & vbTAB & objPackage.PackageID +Next diff --git a/Chapter04/4-3_EnumPackagesAndFolders.vbs b/Chapter04/4-3_EnumPackagesAndFolders.vbs new file mode 100644 index 0000000..8392212 --- /dev/null +++ b/Chapter04/4-3_EnumPackagesAndFolders.vbs @@ -0,0 +1,76 @@ +Const strSMSServer = + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +'for intPackageFolder=0 enumerate from the root package node +' to enumerate from a subfolder, replace the 0 with +' the proper ContainerNodeID +intPackageFolder = 0 +intSpace = 0 +'First, display packages in current folder (as defined +' by intPackageFolder +ListPkgsInFolder "", intPackageFolder, intSpace +'Then enumerate all subfolders of the current folder +DisplaySubFolders intPackageFolder, intSpace + 3 + +Sub DisplaySubFolders(intPackageFolder, intSpace) + Set colItems = objSMS.ExecQuery _ + ("select * from SMS_ObjectContainerNode where " & _ + "ObjectType = 2 and " & _ + "ParentContainerNodeID = " & cint(intPackageFolder)) + For each objContainerItem in colItems + ListPkgsInFolder objContainerItem.Name, _ + objContainerItem.ContainerNodeID,intSpace + 3 + DisplaySubFolders objContainerItem.ContainerNodeID, _ + intSpace + 3 + Next +End Sub + +Sub ListPkgsInFolder(strContainerName, intPkgFolder, intSpace) + If intPkgFolder = 0 then 'we're looking at the root node here + + strSQL = "Select PackageID From SMS_Package where " & _ + "PackageID not in (select InstanceKey " & _ + "from SMS_ObjectContainerItem where ObjectType=2) " & _ + "and ImageFlags = 0" + 'ImageFlags = 0 is used to make sure we don't pick up + 'and image packages from the Operating System Deployment + 'Feature Pack (OSD FP) + Set colPkgs = objSMS.ExecQuery(strSQL) + wscript.echo space(intSpace) & "----" & vbCRLF & _ + space(intSpace) & "Root Collection" + For each objPkg in colPkgs + wscript.echo objPkg.PackageID & vbTAB & _ + GetPackageName(objPkg.PackageID) + Next + Else + Set colItems = objSMS.ExecQuery _ + ("select * from SMS_ObjectContainerItem where " & _ + "ObjectType = 2 and " & _ + "ContainerNodeID = " & cint(intPkgFolder)) + wscript.echo space(intSpace) & "----" & vbCRLF & _ + space(intSpace) & strContainerName + For each objContainerItem in colItems + strPackageID = objContainerItem.InstanceKey + wscript.echo space(intSpace) & strPackageID & vbTAB & _ + GetPackageName(strPackageID) + Next + End If +End Sub + +Function GetPackageName(strPckID) + Set objPackage = GetObject( "WinMgmts:\\" & strSMSServer & _ + "\root\SMS\site_" & strSMSSiteCode & _ + ":SMS_Package.PackageID='" & strPckID & "'") + GetPackageName = objPackage.Name & vbTAB & objPackage.Version +End Function diff --git a/Chapter04/4-4_DeletePackage.vbs b/Chapter04/4-4_DeletePackage.vbs new file mode 100644 index 0000000..2bc6344 --- /dev/null +++ b/Chapter04/4-4_DeletePackage.vbs @@ -0,0 +1,22 @@ +strSMSServer = + +strPackageID = "LAB000CC" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +'Remove Package +Set objPackage = GetObject( "WinMgmts:\\" & strSMSServer & _ + "\root\SMS\site_" & strSMSSiteCode & _ + ":SMS_Package.PackageID='" & strPackageID & "'") +objPackage.Delete_ +wscript.echo "Deleted " & strPackageID diff --git a/Chapter04/4-5_ModPkgSourceLocation.vbs b/Chapter04/4-5_ModPkgSourceLocation.vbs new file mode 100644 index 0000000..8745b2b --- /dev/null +++ b/Chapter04/4-5_ModPkgSourceLocation.vbs @@ -0,0 +1,24 @@ +strSMSServer = + +strPackageID = "LAB0000A" +strSourcePath = "\\smsvpc\Source\867460_1.1SP1" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + + +Set objPackage = GetObject( "WinMgmts:!\\" & strSMSServer & _ + "\root\SMS\site_" & strSMSSiteCode & _ + ":SMS_Package.PackageID='" & strPackageID & "'") +objPackage.PkgSourceFlag = 2 ' specifies direct source +objPackage.PkgSourcePath = strSourcePath +objPackage.Put_ diff --git a/Chapter04/4-6_ModPkgProps.vbs b/Chapter04/4-6_ModPkgProps.vbs new file mode 100644 index 0000000..834105c --- /dev/null +++ b/Chapter04/4-6_ModPkgProps.vbs @@ -0,0 +1,26 @@ +strSMSServer = + +strPackageID = "LAB0000A" +intDisconnectDelay = 5 +blnDisconnectEnabled = True +intDisconnectNumRetries = 2 + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objPackage = GetObject( "WinMgmts:!\\" & strSMSServer & _ + "\root\SMS\site_" & strSMSSiteCode & _ + ":SMS_Package.PackageID='" & strPackageID & "'") +objPackage.ForcedDisconnectDelay = intDisconnectDelay +objPackage.ForcedDisconnectEnabled = blnDisconnectEnabled +objPackage.ForcedDisconnectNumRetries = intDisconnectNumRetries +objPackage.Put_ diff --git a/Chapter04/4-7_ModPkg-DPSettings.vbs b/Chapter04/4-7_ModPkg-DPSettings.vbs new file mode 100644 index 0000000..804b29c --- /dev/null +++ b/Chapter04/4-7_ModPkg-DPSettings.vbs @@ -0,0 +1,22 @@ +strSMSServer = + +strPackageID = "LAB000CE" +strPreferredAddressType = "SMS_LAN_SENDER" +intPriority = 1 + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objPackage = objSMS.Get("SMS_Package.PackageID='" & strPackageID & "'") +objPackage.PreferredAddressType = strPreferredAddressType +objPackage.Priority = intPriority +objPackage.Put_ diff --git a/Chapter04/4-8_ModPkgPerms.vbs b/Chapter04/4-8_ModPkgPerms.vbs new file mode 100644 index 0000000..1e715c7 --- /dev/null +++ b/Chapter04/4-8_ModPkgPerms.vbs @@ -0,0 +1,29 @@ +'This script grants the "Help Desk" Read, Modify, and Distribute +'Permissions to PackageID = LAB00007 +strSMSServer = + +strHelpDesk="SMSVPC\Help Desk" +strPackageID="LAB00007" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objPackage = objSMS.Get("SMS_Package.PackageID='" & strPackageID & "'") +wscript.echo objPackage.PackageID +Set objNewRight = objSWbemServices.Get _ + ("SMS_UserInstancePermissions").SpawnInstance_() +objNewRight.UserName = strHelpDesk +objNewRight.ObjectKey = 2 'package +objNewRight.InstanceKey = objPackage.PackageID +objNewRight.InstancePermissions = 11 + '0000000000001011 (read, modify, distribute) +objNewRight.Put_ diff --git a/Chapter04/4-9_UpdateDP_Sched.vbs b/Chapter04/4-9_UpdateDP_Sched.vbs new file mode 100644 index 0000000..52fdffb --- /dev/null +++ b/Chapter04/4-9_UpdateDP_Sched.vbs @@ -0,0 +1,31 @@ +Const STORAGE_DIRECT=2 +strSMSServer = +strPackageID = "LAB0000A" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set Token = objSMS.Get("SMS_ST_RecurWeekly") +Token.Day = 5 'Thursday +Token.DayDuration = 0 'recur indefinitely +Token.ForNumberOfWeeks = 1 'recur every 1 week +Token.StartTime = "20061202103000.000000+***" 'wmi date-string +'If omitted, StartTime = Jan 1, 1990 - this shouldn't +'cause any issues +Set objPackage = objSMS.Get _ + ("SMS_Package.PackageID='" & strPackageID & "'") +'Make sure package is set to "Always obtain files +' from source directory, then add schedule. +if objPackage.PkgSourceFlag=STORAGE_DIRECT then + objPackage.RefreshSchedule = Array(Token) + objPackage.Put_ +end if diff --git a/Chapter05/5-10_DisplayAllPackagesWithPrograms_andProgramEnvironment.vbs b/Chapter05/5-10_DisplayAllPackagesWithPrograms_andProgramEnvironment.vbs new file mode 100644 index 0000000..57117db --- /dev/null +++ b/Chapter05/5-10_DisplayAllPackagesWithPrograms_andProgramEnvironment.vbs @@ -0,0 +1,61 @@ +strSMSServer = + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set colPackages = objSMS.ExecQuery("Select * From SMS_Package where " & _ + "ImageFlags = 0 order by Name") + +For each objPackage in ColPackages + wscript.echo objPackage.Name & " (" & objPackage.PackageID & ")" + ListPrograms(objPackage.PackageID) +Next + +Sub ListPrograms(strPackageID) + Set objSWbemLocator = CreateObject _ + ("WbemScripting.SWbemLocator") + Set objSMS = objSWbemLocator.ConnectServer _ + (strSMSServer, "root\sms\site_" & strSMSSiteCode ) + Set colPrograms = objSMS.ExecQuery _ + ("Select * From SMS_Program " & _ + "WHERE PackageID='" & strPackageID & _ + "' order by ProgramName") + For Each objProgram In colPrograms + wscript.echo vbTAB & objProgram.ProgramName & vbTAB & _ + GetUserLogonRequirement(strPackageID, _ + objProgram.ProgramName) + Next +End Sub + +Function GetUserLogonRequirement(strPackageID, strProgramName) + USER_LOGGED_ON = 2^(14-1) + WHETHER_OR_NOT_USER_LOGGED_ON = 2^(15-1) + NO_USER_LOGGED_ON = 2^(17-1) + + Set objProgram=objSMS.Get _ + ("SMS_Program.PackageID='" & strPackageID & "',ProgramName='" & _ + strProgramName & "'") + + intProgramFlags = objProgram.ProgramFlags + + if (intProgramFlags and USER_LOGGED_ON) then + strInfo = "Only when a user is logged on." + elseif _ + (intProgramFlags and WHETHER_OR_NOT_USER_LOGGED_ON) then + strInfo = "Whether or not a user is logged on." + elseif (intProgramFlags and NO_USER_LOGGED_ON) then + strInfo = "Only when no user is logged on." + else + + end if + GetUserLogonRequirement = strInfo +End Function diff --git a/Chapter05/5-11_ShowAllProgramsWithDependencies.vbs b/Chapter05/5-11_ShowAllProgramsWithDependencies.vbs new file mode 100644 index 0000000..13ccbc6 --- /dev/null +++ b/Chapter05/5-11_ShowAllProgramsWithDependencies.vbs @@ -0,0 +1,31 @@ +strSMSServer = + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + + Set colPrograms = objSMS.ExecQuery("Select * From SMS_Program " & _ + "WHERE DependentProgram <> '' order by PackageID") + +for each objProgram in colPrograms + wscript.echo "Package Name: " & GetPackageName _ + (objProgram.PackageID) & "(" & objProgram.PackageID & ")" + wscript.echo vbTAB & "Program Name: " & _ + objProgram.ProgramName + wscript.echo vbTAB & vbTAB & _ + "Dependent PackageID;;Program: " & _ + objProgram.DependentProgram +next + +Function GetPackageName(strPckID) + Set objPackage=objSMS.Get("SMS_Package.PackageID='" & strPckID & "'") + GetPackageName = objPackage.Name +End Function diff --git a/Chapter05/5-12_ConfigRunFrequency.vbs b/Chapter05/5-12_ConfigRunFrequency.vbs new file mode 100644 index 0000000..b0d0e31 --- /dev/null +++ b/Chapter05/5-12_ConfigRunFrequency.vbs @@ -0,0 +1,26 @@ +EVERYUSER = 2^(16) + +strSMSServer = + +strPackageID = "LAB0000A" +strProgramName = "NET Framework 1.1 SP1" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objProgram=objSMS.Get("SMS_Program.PackageID='" & _ + strPackageID & "',ProgramName='" & strProgramName & "'") + +intProgramFlags = objProgram.ProgramFlags +intProgramFlags = intProgramFlags and not EVERYUSER +objProgram.ProgramFlags = intProgramFlags +objProgram.Put_ diff --git a/Chapter05/5-13_ShowAllProgramsWithNotificationsSet.vbs b/Chapter05/5-13_ShowAllProgramsWithNotificationsSet.vbs new file mode 100644 index 0000000..c876ff4 --- /dev/null +++ b/Chapter05/5-13_ShowAllProgramsWithNotificationsSet.vbs @@ -0,0 +1,35 @@ +SUPPRESS_NOTIFICATIONS = 2^(10) + +strSMSServer = + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set colPrograms = objSMS.ExecQuery _ + ("Select * From SMS_Program order by PackageID") + +wscript.echo "All Programs with 'Suppress Program " & _ + "Notifications' configured." +for each objProgram in colPrograms + if (objProgram.ProgramFlags and SUPPRESS_NOTIFICATIONS) then + wscript.echo objProgram.ProgramName & vbTAB & _ + GetPackageName(objProgram.PackageID) & "(" & _ + objProgram.PackageID & ")" + end if +next + +Function GetPackageName(strPckID) + Set objPackage=objSMS.Get _ + ("SMS_Package.PackageID='" & _ + strPckID & "'") + GetPackageName = objPackage.Name +End Function \ No newline at end of file diff --git a/Chapter05/5-14_DisableProgram.vbs b/Chapter05/5-14_DisableProgram.vbs new file mode 100644 index 0000000..5273195 --- /dev/null +++ b/Chapter05/5-14_DisableProgram.vbs @@ -0,0 +1,34 @@ +DISABLE_PROGRAM = 2^(12) + +strSMSServer = + +strPackageID = "LAB0000A" +strProgramName = "NET Framework 1.1 SP1" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objProgram=objSMS.Get("SMS_Program.PackageID='" & _ + strPackageID & "',ProgramName='" & strProgramName & "'") + +intProgramFlags = objProgram.ProgramFlags + +if (intProgramFlags and DISABLE_PROGRAM) then + wscript.echo "DISABLE_PROGRAM flag " & _ + "already set!" +else + wscript.echo "Setting DISABLE_PROGRAM flag" + intProgramFlags = intProgramFlags or _ + DISABLE_PROGRAM + objProgram.ProgramFlags = intProgramFlags + objProgram.Put_ +end if diff --git a/Chapter05/5-15_ShowAllDisabledPrograms.vbs b/Chapter05/5-15_ShowAllDisabledPrograms.vbs new file mode 100644 index 0000000..3d653b5 --- /dev/null +++ b/Chapter05/5-15_ShowAllDisabledPrograms.vbs @@ -0,0 +1,38 @@ +strSMSServer = + +DISABLE_PROGRAM = 2^(12) + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set colPrograms = objSMS.ExecQuery _ + ("Select * From SMS_Program order by PackageID") +For Each objProgram In colPrograms + if (objProgram.ProgramFlags and DISABLE_PROGRAM) then + wscript.echo "Program Name: " & _ + objProgram.ProgramName & vbTAB & _ + "Package Name: " & _ + GetPackageName(objProgram.PackageID) & " (" & _ + objProgram.PackageID & ")" + end if +Next + +Function GetPackageName(strPckID) + Set objSWbemLocator = CreateObject _ + ("WbemScripting.SWbemLocator") + Set objSMS = objSWbemLocator.ConnectServer _ + (strSMSServer, "root\sms\site_" & strSMSSiteCode ) + Set objPackage=objSMS.Get _ + ("SMS_Package.PackageID='" & _ + strPckID & "'") + GetPackageName = objPackage.Name +End Function diff --git a/Chapter05/5-16_Re-EnableProgram.vbs b/Chapter05/5-16_Re-EnableProgram.vbs new file mode 100644 index 0000000..ed94cfc --- /dev/null +++ b/Chapter05/5-16_Re-EnableProgram.vbs @@ -0,0 +1,34 @@ +DISABLE_PROGRAM = 2^(12) + +strSMSServer = + +strPackageID = "LAB0000C" +strProgramName = "NET Framework 1.1 SP1" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objProgram=objSMS.Get("SMS_Program.PackageID='" & _ + strPackageID & "',ProgramName='" & strProgramName & "'") + +intProgramFlags = objProgram.ProgramFlags + +if (intProgramFlags and DISABLE_PROGRAM) then + wscript.echo "Re-enabling disabled program" + intProgramFlags = intProgramFlags and not _ + DISABLE_PROGRAM + objProgram.ProgramFlags = intProgramFlags + objProgram.Put_ +else + wscript.echo "DISABLE_PROGRAM flag not set" +end if + diff --git a/Chapter05/5-17_ShowAllPackagesProgramsWithWindowsInstallerSourcesConfigured.vbs b/Chapter05/5-17_ShowAllPackagesProgramsWithWindowsInstallerSourcesConfigured.vbs new file mode 100644 index 0000000..90ffaba --- /dev/null +++ b/Chapter05/5-17_ShowAllPackagesProgramsWithWindowsInstallerSourcesConfigured.vbs @@ -0,0 +1,31 @@ +strSMSServer = + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set colPrograms = objSMS.ExecQuery _ + ("Select * From SMS_Program " & _ + "WHERE MSIProductID <> '' order by PackageID") + +for each objProgram in colPrograms + wscript.echo "Package Name: " & GetPackageName _ + (objProgram.PackageID) & "(" & objProgram.PackageID & ")" + wscript.echo vbTAB & "Program Name: " & _ + objProgram.ProgramName + wscript.echo vbTAB & vbTAB & "MSIFilePath MSIProductID: " & _ + objProgram.MSIFilePath & " " & objProgram.MSIProductID +next + +Function GetPackageName(strPckID) + Set objPackage=objSMS.Get("SMS_Package.PackageID='" & strPckID & "'") + GetPackageName = objPackage.Name +End Function diff --git a/Chapter05/5-18_EnableMOMAlerts.vbs b/Chapter05/5-18_EnableMOMAlerts.vbs new file mode 100644 index 0000000..a70633a --- /dev/null +++ b/Chapter05/5-18_EnableMOMAlerts.vbs @@ -0,0 +1,45 @@ +DISABLE_MOM_ALERT_WHILE_RUNNING = 2^(5) +GENERATE_MOM_ALERT_IF_FAILURE = 2^(6) + +strSMSServer = + +strPackageID = "LAB0000A" +strProgramName = "NET Framework 1.1 SP1" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objProgram=objSMS.Get("SMS_Program.PackageID='" & _ + strPackageID & "',ProgramName='" & strProgramName & "'") + +intProgramFlags = objProgram.ProgramFlags + +if (intProgramFlags and DISABLE_MOM_ALERT_WHILE_RUNNING) then + wscript.echo "DISABLE_MOM_ALERT_WHILE_RUNNING flag " & _ + "already set!" +else + wscript.echo "Setting DISABLE_MOM_ALERT_WHILE_RUNNING flag" + intProgramFlags = intProgramFlags or _ + DISABLE_MOM_ALERT_WHILE_RUNNING +end if + +if (intProgramFlags and GENERATE_MOM_ALERT_IF_FAILURE) then + wscript.echo "GENERATE_MOM_ALERT_IF_FAILURE flag " & _ + "already set!" +else + wscript.echo "Setting GENERATE_MOM_ALERT_IF_FAILURE flag" + intProgramFlags = intProgramFlags or _ + GENERATE_MOM_ALERT_IF_FAILURE +end if +objProgram.ProgramFlags = intProgramFlags +objProgram.Put_ + diff --git a/Chapter05/5-19_ExportingPackageProgramtoMOF.vbs b/Chapter05/5-19_ExportingPackageProgramtoMOF.vbs new file mode 100644 index 0000000..d93793b --- /dev/null +++ b/Chapter05/5-19_ExportingPackageProgramtoMOF.vbs @@ -0,0 +1,97 @@ +'you could use a for-loop in batch to bring in every .mof in a directory: for /F %G in ('dir /b') do mofcomp %G +Const ForWriting = 2 +Set fso = CreateObject("Scripting.FileSystemObject") +strSMSServer = "SMSVPC" +strNEWSMSServer = "MYPRODSMSSERVER" +strNewSMSSiteCode = "PRD" +strPackageID = "LAB0000B" +strExportFolder = "C:\Scripts\Packages\" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + + +Set colPkgs = objSMS.ExecQuery _ + ("select * from SMS_Package where PackageID = '" & strPackageID & "'") + +for each objPkg in colPkgs +'wscript.echo objPkg.GetObjectText_ +'wscript.echo objPkg.GetText_(2) 'output to xml + wscript.echo "Exporting " & objPkg.Name & vbTAB & _ + objPkg.PackageID + Set fout = fso.OpenTextFile(strExportFolder & _ + objPkg.Name & " (" & objPkg.PackageID & ")" & _ + ".MOF", ForWriting, True) + fout.writeline "//********************************" + fout.writeline "//Created by VBScript" & vbTAB & Now() + fout.writeline "//********************************" + fout.writeline vbCRLF + 'only use the following line if planning to import MOF + 'from the command line + fout.writeline "#pragma namespace(" & chr(34) & "\\\\" & _ + strNEWSMSServer & "\\root\\SMS\\site_" & _ + strnewSMSSiteCode & chr(34) & ")" + + 'Write the package info + fout.writeline vbCRLF + fout.writeline "// **** Class : SMS_Package ****" + + for each strLine in split(objPkg.GetObjectText_, chr(10)) + if instr(strLine, "PackageID =") then + fout.writeline(vbTAB & "PackageID = " & chr(34) & _ + chr(34)) & ";" + elseif instr(strLine, "instance of SMS_Package") then + strLine = "instance of SMS_Package as $pID" + fout.writeline cstr(strLine) + elseif instr(strLine, "SourceDate") then + strLine = "SourceDate = " & Chr(34) & Chr(34) + fout.writeline cstr(strLine) + elseif instr(strLine, "SourceSite") then + strLine = "SourceSite = " & Chr(34) & Chr(34) + fout.writeline cstr(strLine) + elseif instr(strLine, "SourceVersion") then + strLine = "SourceVersion = " & Chr(34) & Chr(34) + fout.writeline cstr(strLine) + else + fout.writeline cstr(strLine) + end if + next + + 'now write program info + fout.writeline vbCRLF + fout.writeline "// **** Class : SMS_Program ****" + + Set colPrograms = objSMS.ExecQuery _ + ("select * from SMS_Program where PackageID = '" & _ + objPkg.PackageID & "'") + + for each objProgram in colPrograms + for each strLine in split(objProgram.GetObjectText_, chr(10)) + if instr(strLine, "PackageID =") then + fout.writeline(vbTAB & "PackageID = $pID;") + elseif instr(strLine, "DependentProgram") then + if len(strLine) = 23 then + fout.writeline strLine + else + fout.writeline vbTAB & "//" & strLine + fout.writeline vbTAB & "DependentProgram = " & _ + Chr(34) & Chr(34) & ";" + end if + else + fout.writeline cstr(strLine) + end if + next + next + fout.writeline "// **** End ****" + fout.close +next + + diff --git a/Chapter05/5-1_CreateProgram.vbs b/Chapter05/5-1_CreateProgram.vbs new file mode 100644 index 0000000..dce9908 --- /dev/null +++ b/Chapter05/5-1_CreateProgram.vbs @@ -0,0 +1,23 @@ +strSMSServer = +strPackageID = "LAB0000A" +strProgramName = "NET Framework 1.1 SP1" +strProgramCMDLine = _ + "NDP1.1sp1-KB867460-X86.exe /I /Q /L:%temp%\NetFW1.1.sp1.log" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set newProgram = objSMS.Get("SMS_Program").SpawnInstance_() +newProgram.PackageID = strPackageID +newProgram.ProgramName = strProgramName +newProgram.CommandLine = strProgramCMDLine +newProgram.Put_ diff --git a/Chapter05/5-20_ExportingALLPackageProgramtoMOFs.vbs b/Chapter05/5-20_ExportingALLPackageProgramtoMOFs.vbs new file mode 100644 index 0000000..6d9d94b --- /dev/null +++ b/Chapter05/5-20_ExportingALLPackageProgramtoMOFs.vbs @@ -0,0 +1,93 @@ +'you could use a for-loop in batch to bring in every .mof in a directory: for /F %G in ('dir /b') do mofcomp %G +Const ForWriting = 2 +Set fso = CreateObject("Scripting.FileSystemObject") +strSMSServer = "SMSVPC" +strNEWSMSServer = "MYPRODSMSSERVER" +strNewSMSSiteCode = "PRD" +strExportFolder = "C:\Scripts\Packages\" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set colPkgs = objSMS.ExecQuery _ +("select * from SMS_Package") + +for each objPkg in colPkgs +'wscript.echo objPkg.GetObjectText_ +'wscript.echo objPkg.GetText_(2) 'output to xml + wscript.echo "Exporting " & objPkg.Name & vbTAB & _ + objPkg.PackageID + Set fout = fso.OpenTextFile(strExportFolder & _ + objPkg.Name & " (" & objPkg.PackageID & ")" & ".MOF", ForWriting, True) + fout.writeline "//********************************" + fout.writeline "//Created by VBScript" & vbTAB & Now() + fout.writeline "//********************************" + fout.writeline vbCRLF + 'only use the following line if planning to import MOF + 'from the command line + fout.writeline "#pragma namespace(" & chr(34) & "\\\\" & _ + strNEWSMSServer & "\\root\\SMS\\site_" & _ + strnewSMSSiteCode & chr(34) & ")" + + 'Write the package info + fout.writeline vbCRLF + fout.writeline "// **** Class : SMS_Package ****" + + for each strLine in split(objPkg.GetObjectText_, chr(10)) + if instr(strLine, "PackageID =") then + fout.writeline(vbTAB & "PackageID = " & chr(34) & _ + chr(34)) & ";" + elseif instr(strLine, "instance of SMS_Package") then + strLine = "instance of SMS_Package as $pID" + fout.writeline cstr(strLine) + elseif instr(strLine, "SourceDate") then + strLine = "SourceDate = " & Chr(34) & Chr(34) + fout.writeline cstr(strLine) + elseif instr(strLine, "SourceSite") then + strLine = "SourceSite = " & Chr(34) & Chr(34) + fout.writeline cstr(strLine) + elseif instr(strLine, "SourceVersion") then + strLine = "SourceVersion = " & Chr(34) & Chr(34) + fout.writeline cstr(strLine) + else + fout.writeline cstr(strLine) + end if + next + + 'now write program info + fout.writeline vbCRLF + fout.writeline "// **** Class : SMS_Program ****" + + Set colPrograms = objSMS.ExecQuery _ + ("select * from SMS_Program where PackageID = '" & _ + objPkg.PackageID & "'") + + for each objProgram in colPrograms + for each strLine in split(objProgram.GetObjectText_, chr(10)) + if instr(strLine, "PackageID =") then + fout.writeline(vbTAB & "PackageID = $pID;") + elseif instr(strLine, "DependentProgram") then + if len(strLine) = 23 then + fout.writeline strLine + else + fout.writeline vbTAB & "//" & strLine + fout.writeline vbTAB & "DependentProgram = " & Chr(34) & Chr(34) & ";" + end if + else + fout.writeline cstr(strLine) + end if + next + next + fout.writeline "// **** End ****" + fout.close +next + + diff --git a/Chapter05/5-2_DeleteProgram.vbs b/Chapter05/5-2_DeleteProgram.vbs new file mode 100644 index 0000000..0415575 --- /dev/null +++ b/Chapter05/5-2_DeleteProgram.vbs @@ -0,0 +1,21 @@ +strSMSServer = + +strPackageID = "LAB0000B" +strProgramName = "NET Framework 1.1 SP1" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objProgram=objSMS.Get("SMS_Program.PackageID='" & _ + strPackageID & "',ProgramName='" & strProgramName & "'") +wscript.echo "Deleting " & objProgram.ProgramName +objProgram.Delete_ \ No newline at end of file diff --git a/Chapter05/5-3_DeletePrograms.vbs b/Chapter05/5-3_DeletePrograms.vbs new file mode 100644 index 0000000..e95dca1 --- /dev/null +++ b/Chapter05/5-3_DeletePrograms.vbs @@ -0,0 +1,22 @@ +strSMSServer = +strPackageID = "LAB0000B" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set colPrograms = objSMS.ExecQuery("Select * From SMS_Program " & _ + "WHERE PackageID='" & strPackageID & "'") +For Each objProgram In colPrograms + wscript.echo "Deleting " & objProgram.ProgramName + objProgram.Delete_ +Next + diff --git a/Chapter05/5-4_ViewingAllProgramsInAPackage.vbs b/Chapter05/5-4_ViewingAllProgramsInAPackage.vbs new file mode 100644 index 0000000..913e69d --- /dev/null +++ b/Chapter05/5-4_ViewingAllProgramsInAPackage.vbs @@ -0,0 +1,28 @@ +strSMSServer = +strPackageID = "LAB0000C" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set colPrograms = objSMS.ExecQuery("Select * From SMS_Program " & _ + "WHERE PackageID='" & strPackageID & "' order by ProgramName") +wscript.echo "All Programs for " & _ + GetPackageName(strPackageID) & " (" & strPackageID & ")" +For Each objProgram In colPrograms + wscript.echo vbTAB & objProgram.ProgramName +Next + +Function GetPackageName(strPckID) + Set objPackage=objSMS.Get("SMS_Package.PackageID='" & strPckID & "'") + GetPackageName = objPackage.Name +End Function + diff --git a/Chapter05/5-5_ViewingAllPackagesWithPrograms.vbs b/Chapter05/5-5_ViewingAllPackagesWithPrograms.vbs new file mode 100644 index 0000000..a7ded48 --- /dev/null +++ b/Chapter05/5-5_ViewingAllPackagesWithPrograms.vbs @@ -0,0 +1,29 @@ +strSMSServer = + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set colPackages = objSMS.ExecQuery("Select * From SMS_Package where " & _ + "ImageFlags = 0 order by Name") + +For each objPackage in ColPackages + wscript.echo objPackage.Name & " (" & objPackage.PackageID & ")" + ListPrograms(objPackage.PackageID) +Next + +Sub ListPrograms(strPackageID) + Set colPrograms = objSMS.ExecQuery("Select * From SMS_Program " & _ + "WHERE PackageID='" & strPackageID & "' order by ProgramName") + For Each objProgram In colPrograms + wscript.echo vbTAB & objProgram.ProgramName + Next +End Sub diff --git a/Chapter05/5-6_ModifyProgram.vbs b/Chapter05/5-6_ModifyProgram.vbs new file mode 100644 index 0000000..e58b959 --- /dev/null +++ b/Chapter05/5-6_ModifyProgram.vbs @@ -0,0 +1,22 @@ +strSMSServer = + +strPackageID = "LAB0000A" +strProgramName = "NET Framework 1.1 SP1" +strComment = "This program installs SP1 for the .NET framework" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objProgram=objSMS.Get("SMS_Program.PackageID='" & _ + strPackageID & "',ProgramName='" & strProgramName & "'") +objProgram.Comment = strComment +objProgram.Put_ diff --git a/Chapter05/5-7_ModifyCategoryOnMultiplePrograms.vbs b/Chapter05/5-7_ModifyCategoryOnMultiplePrograms.vbs new file mode 100644 index 0000000..f9eb23e --- /dev/null +++ b/Chapter05/5-7_ModifyCategoryOnMultiplePrograms.vbs @@ -0,0 +1,30 @@ +strSMSServer = + +strCategory = "SMS Admin" + +strPkgList = "LAB00002,LAB00006,LAB00003,LAB00005" +arrPackages = split(strPkgList,",") + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +For each strPackageID in arrPackages + Set colPrograms = objSMS.ExecQuery _ + ("Select * From SMS_Program " & _ + "WHERE PackageID='" & strPackageID & "'") + For Each objProgram In colPrograms + wscript.echo "Modifying category for:" & _ + objProgram.ProgramName + objProgram.Description = strCategory + objProgram.Put_ + Next +Next \ No newline at end of file diff --git a/Chapter05/5-8_ShowSupportedPlatforms.vbs b/Chapter05/5-8_ShowSupportedPlatforms.vbs new file mode 100644 index 0000000..54dd1c0 --- /dev/null +++ b/Chapter05/5-8_ShowSupportedPlatforms.vbs @@ -0,0 +1,41 @@ +strSMSServer = + +ANY_PLATFORM = 2^(27) 'sms doc incorrect + +strPackageID = "LAB00086" +strProgramName = "Microsoft Updates" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objProgram=objSMS.Get("SMS_Program.PackageID='" & _ + strPackageID & "',ProgramName='" & strProgramName & "'") + +'Check for "Any Platform in ProgramFlags first +if (objProgram.ProgramFlags and ANY_PLATFORM) then + wscript.echo "This program is configured to run " & _ + "on any platform" +else + for i = 0 to ubound(objProgram.SupportedOperatingSystems) + strInfo = _ + objProgram.SupportedOperatingSystems(i).Name & vbTAB + strInfo = strInfo & _ + objProgram.SupportedOperatingSystems(i).Platform & _ + vbTAB + strInfo = strInfo & _ + objProgram.SupportedOperatingSystems(i). _ + MinVersion & vbTAB + strInfo = strInfo & objProgram. _ + SupportedOperatingSystems(i).MaxVersion + wscript.echo strInfo + next +end if diff --git a/Chapter05/5-9_ShowAllExplicitPlatformsWO2K.vbs b/Chapter05/5-9_ShowAllExplicitPlatformsWO2K.vbs new file mode 100644 index 0000000..b15df09 --- /dev/null +++ b/Chapter05/5-9_ShowAllExplicitPlatformsWO2K.vbs @@ -0,0 +1,57 @@ +strSMSServer = + +strWindowsVersion = "5.00" 'looking for Windows 2000 here +ANY_PLATFORM = 2^(27) + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set colPrograms = objSMS.ExecQuery _ + ("Select * From SMS_Program order by PackageID") +For Each objProgram In colPrograms + if (objProgram.ProgramFlags and ANY_PLATFORM) then + 'program is set to "any platform" - don't check further + else + ListFilteredPrograms objProgram.ProgramName, objProgram.PackageID, _ + strWindowsVersion + end if +Next + +Sub ListFilteredPrograms(strProgramName, strPackageID, strWinVer) + Set objProgram=objSMS.Get _ + ("SMS_Program.PackageID='" & _ + strPackageID & "',ProgramName='" & _ + strProgramName & "'") + for i = 0 to ubound(objProgram.SupportedOperatingSystems) + if instr(objProgram.SupportedOperatingSystems(i). _ + MaxVersion, strWinVer) then + blnFoundOne = true + end if + next + if blnFoundOne then + wscript.echo "Package Name:" & _ + GetPackageName(strPackageID) & vbTAB & _ + "Program Name:" & strProgramName + else + 'this would capture all programs that had supported + 'platforms configured that did not contain strWinVer + end if +End Sub + +Function GetPackageName(strPckID) + Set objPackage=objSMS.Get _ + ("SMS_Package.PackageID='" & _ + strPckID & "'") + GetPackageName = objPackage.Name +End Function + + diff --git a/Chapter05/5-BonusConfigCmdLinProps.vbs b/Chapter05/5-BonusConfigCmdLinProps.vbs new file mode 100644 index 0000000..7fbd37f --- /dev/null +++ b/Chapter05/5-BonusConfigCmdLinProps.vbs @@ -0,0 +1,57 @@ +RUN_MAXIMIZED = 2^(23) +RUN_MINIMIZED = 2^(22) +HIDE_WINDOW = 2^(24) + +LOGOFF_USER = 2^(25) +SMS_RESTART = 2^(19) +PROGRAM_RESTART = 2^(18) + +strSMSServer = + +strPackageID = "LAB0000C" +strProgramName = "sdktest2" +strCategory = "Developer" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objProgram=objSMS.Get("SMS_Program.PackageID='" & _ + strPackageID & "',ProgramName='" & strProgramName & "'") + +objProgram.CommandLine = "msiexec.exe /q ALLUSERS=2 " & _ + "/m MSI4LYMT /i " & chr(34) & "SMSSDKSetup.msi" & chr(34) +intProgramFlags = objProgram.ProgramFlags +if (intProgramFlags and RUN_MAXIMIZED) then + wscript.echo "RUN_MAXIMIZED already configured!" +else + 'ensure HIDE_WINDOW and RUN_MINIMIZED are not enabled. + intProgramFlags = intProgramFlags and not HIDE_WINDOW + intProgramFlags = intProgramFlags and not RUN_MINIMIZED + wscript.echo "Configuring Program to RUN_MAXIMIZED" + intProgramFlags = intProgramFlags or RUN_MAXIMIZED +end if + +if (intProgramFlags and SMS_RESTART) then + wscript.echo "SMS_RESTART already configured!" +else + 'ensure LOGOFF_USER and PROGRAM_RESTART are not enabled. + intProgramFlags = intProgramFlags and not LOGOFF_USER + intProgramFlags = intProgramFlags and not PROGRAM_RESTART + wscript.echo "Configuring Program to SMS_RESTART" + intProgramFlags = intProgramFlags or SMS_RESTART +end if +objProgram.ProgramFlags = intProgramFlags +objProgram.Description = strCategory 'description is actually the program "category" +objProgram.Put_ + + + diff --git a/Chapter06/6-10_ModAdvert_RecurringSMS_ST_RecurMonthlyByDate.vbs b/Chapter06/6-10_ModAdvert_RecurringSMS_ST_RecurMonthlyByDate.vbs new file mode 100644 index 0000000..71f1efe --- /dev/null +++ b/Chapter06/6-10_ModAdvert_RecurringSMS_ST_RecurMonthlyByDate.vbs @@ -0,0 +1,60 @@ +strSMSServer = + +strAdvertID = "LAB20016" +'"occurs day 5 of every two months beginning now()" +'For advStartTime, 'Now()' is used to get the current +'date/time of the system. A properly fomatted date/time would +'just fine here also: e.g., "12/02/2006 12:59 AM" +advStartTime = Now() + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +'''''''''''''Schedule Token Information +'Create a new instance of SMS_ST_RecurInterval +Set advNewRecurToken = objSMS.Get("SMS_ST_RecurMonthlyByDate"). _ + SpawnInstance_() +advNewRecurToken.ForNumberOfMonths = 2 +advNewRecurToken.MonthDay = 5 'set to zero for last day of month +advNewRecurToken.StartTime = ConvertToWMIDate(advStartTime) +'''''''''''''END Schedule Token Information + +retval = AddSchedToken(advNewRecurToken, strAdvertID) + +Function AddSchedToken(objSchedToken, strAdvertID) + 'enlarge the current schedule array by 1 + Set objAdvert=objSMS.Get _ + ("SMS_Advertisement.AdvertisementID='" & strAdvertID & "'") + advertArray = objAdvert.AssignedSchedule + onemore = ubound(advertArray) + 1 + redim preserve advertArray(onemore) + objAdvert.AssignedSchedule = advertArray + 'add the new assignment + objAdvert.AssignedSchedule(onemore) = objSchedToken + objadvert.AssignedScheduleEnabled = True + AddSchedToken = objAdvert.Put_ +End Function + +Function ConvertToWMIDate(strDate) + 'Convert from a standard date time to wmi date + '4/18/2005 11:30:00 AM = 2005041811300.000000+*** + strYear = year(strDate):strMonth = month(strDate) + strDay = day(strDate):strHour = hour(strDate) + strMinute = minute(strDate) + 'Pad single digits with leading zero + if len(strmonth) = 1 then strMonth = "0" & strMonth + if len(strDay) = 1 then strDay = "0" & strDay + if len(strHour) = 1 then strHour = "0" & strHour + if len(strMinute) = 1 then strMinute = "0" & strMinute + ConvertToWMIDate = strYear & strMonth & strDay & strHour _ + & strMinute & "00.000000+***" +end function diff --git a/Chapter06/6-11_ModAdvert_RecurringSMS_ST_RecurMonthlyByWeekDay.vbs b/Chapter06/6-11_ModAdvert_RecurringSMS_ST_RecurMonthlyByWeekDay.vbs new file mode 100644 index 0000000..9c2d1b0 --- /dev/null +++ b/Chapter06/6-11_ModAdvert_RecurringSMS_ST_RecurMonthlyByWeekDay.vbs @@ -0,0 +1,67 @@ +strSMSServer = + +strAdvertID = "LAB20016" +'"Occurs the second Monday of every 4 months starting now()" +'For advStartTime, 'Now()' is used to get the current +'date/time of the system. A properly fomatted date/time would +'just fine here also: e.g., "12/02/2006 12:59 AM" +advStartTime = Now() + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +'''''''''''''Schedule Token Information +'Create a new instance of SMS_ST_RecurInterval +Set advNewRecurToken = objSMS.Get("SMS_ST_RecurMonthlyByWeekday"). _ + SpawnInstance_() +advNewRecurToken.ForNumberOfMonths = 4 +advNewRecurToken.Day = 2 '2=Monday +advNewRecurToken.WeekOrder = 2 '2=Second week of month +advNewRecurToken.StartTime = ConvertToWMIDate(advStartTime) +'''''''''''''END Schedule Token Information + +retval = AddSchedToken(advNewRecurToken, strAdvertID) + +Function AddSchedToken(objSchedToken, strAdvertID) + 'enlarge the current schedule array by 1 + Set objAdvert=objSMS.Get _ + ("SMS_Advertisement.AdvertisementID='" & strAdvertID & "'") + advertArray = objAdvert.AssignedSchedule + onemore = ubound(advertArray) + 1 + redim preserve advertArray(onemore) + objAdvert.AssignedSchedule = advertArray + 'add the new assignment + objAdvert.AssignedSchedule(onemore) = objSchedToken + objadvert.AssignedScheduleEnabled = True + AddSchedToken = objAdvert.Put_ +End Function + +Function ConvertToWMIDate(strDate) + 'Convert from a standard date time to wmi date + '4/18/2005 11:30:00 AM = 2005041811300.000000+*** + strYear = year(strDate):strMonth = month(strDate) + strDay = day(strDate):strHour = hour(strDate) + strMinute = minute(strDate) + 'Pad single digits with leading zero + if len(strmonth) = 1 then strMonth = "0" & strMonth + if len(strDay) = 1 then strDay = "0" & strDay + if len(strHour) = 1 then strHour = "0" & strHour + if len(strMinute) = 1 then strMinute = "0" & strMinute + ConvertToWMIDate = strYear & strMonth & strDay & strHour _ + & strMinute & "00.000000+***" +end function + +'1=sunday, 2=monday, ...7 =sat +''0=last week of month + +' Remarks +' Network Discovery is the only SMS component that uses the duration properties. diff --git a/Chapter06/6-12_ModAdvert_RecurringSMS_ST_RecurWeekly.vbs b/Chapter06/6-12_ModAdvert_RecurringSMS_ST_RecurWeekly.vbs new file mode 100644 index 0000000..8c5df6b --- /dev/null +++ b/Chapter06/6-12_ModAdvert_RecurringSMS_ST_RecurWeekly.vbs @@ -0,0 +1,63 @@ +strSMSServer = + +strAdvertID = "LAB20016" +'"Occurs every two weeks on Monday, beginning now()" +'For advStartTime, 'Now()' is used to get the current +'date/time of the system. A properly fomatted date/time would +'just fine here also: e.g., "12/02/2006 12:59 AM" +advStartTime = Now() + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +'''''''''''''Schedule Token Information +'Create a new instance of SMS_ST_RecurInterval +Set advNewRecurToken = objSMS.Get("SMS_ST_RecurWeekly"). _ + SpawnInstance_() +advNewRecurToken.Day = 2 '2=Monday +advNewRecurToken.ForNumberOfWeeks = 2 +advNewRecurToken.StartTime = ConvertToWMIDate(advStartTime) +'''''''''''''END Schedule Token Information + +retval = AddSchedToken(advNewRecurToken, strAdvertID) + +Function AddSchedToken(objSchedToken, strAdvertID) + 'enlarge the current schedule array by 1 + Set objAdvert=objSMS.Get _ + ("SMS_Advertisement.AdvertisementID='" & strAdvertID & "'") + advertArray = objAdvert.AssignedSchedule + onemore = ubound(advertArray) + 1 + redim preserve advertArray(onemore) + objAdvert.AssignedSchedule = advertArray + 'add the new assignment + objAdvert.AssignedSchedule(onemore) = objSchedToken + objadvert.AssignedScheduleEnabled = True + AddSchedToken = objAdvert.Put_ +End Function + +Function ConvertToWMIDate(strDate) + 'Convert from a standard date time to wmi date + '4/18/2005 11:30:00 AM = 2005041811300.000000+*** + strYear = year(strDate):strMonth = month(strDate) + strDay = day(strDate):strHour = hour(strDate) + strMinute = minute(strDate) + 'Pad single digits with leading zero + if len(strmonth) = 1 then strMonth = "0" & strMonth + if len(strDay) = 1 then strDay = "0" & strDay + if len(strHour) = 1 then strHour = "0" & strHour + if len(strMinute) = 1 then strMinute = "0" & strMinute + ConvertToWMIDate = strYear & strMonth & strDay & strHour _ + & strMinute & "00.000000+***" +end function + +'1=sunday, 2=monday, ...7 =sat +''0=last week of month diff --git a/Chapter06/6-13-Bonus_ModAdvert_RunOnUserLogoff.vbs b/Chapter06/6-13-Bonus_ModAdvert_RunOnUserLogoff.vbs new file mode 100644 index 0000000..a1bea4f --- /dev/null +++ b/Chapter06/6-13-Bonus_ModAdvert_RunOnUserLogoff.vbs @@ -0,0 +1,44 @@ +ONUSERLOGOFF = 2^(10) +NO_DISPLAY = 2^(25) + +strSMSServer = + +strAdvertID = "LAB20016" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objAdvertisement = objSMS.Get _ + ("SMS_Advertisement.AdvertisementID='" & strAdvertID & "'") + +intAdvertFlags = objAdvertisement.AdvertFlags +if (intAdvertFlags and ONUSERLOGOFF) then + wscript.echo "ONUSERLOGOFF flag " & _ + "already set!" +else + wscript.echo "Setting ONUSERLOGOFF flag" + intAdvertFlags = intAdvertFlags or _ + ONUSERLOGOFF +end if +if (intAdvertFlags and NO_DISPLAY) then + 'allow users to run program independent of assignment + wscript.echo "Clearing NO_DISPLAY flag" + intAdvertFlags = intAdvertFlags and not _ + NO_DISPLAY + +else + 'allow users to run program independent of assignment + ' already enabled + wscript.echo "NO_DISPLAY flag already cleared!" +end if +objAdvertisement.AdvertFlags = intAdvertFlags +objAdvertisement.Put_ diff --git a/Chapter06/6-13-Bonus_ModAdvert_RunOnUserLogon.vbs b/Chapter06/6-13-Bonus_ModAdvert_RunOnUserLogon.vbs new file mode 100644 index 0000000..85065e1 --- /dev/null +++ b/Chapter06/6-13-Bonus_ModAdvert_RunOnUserLogon.vbs @@ -0,0 +1,33 @@ +ONUSERLOGON = 2^(9) + +strSMSServer = + +strAdvertID = "LAB20016" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objAdvertisement = objSMS.Get _ + ("SMS_Advertisement.AdvertisementID='" & strAdvertID & "'") + +intAdvertFlags = objAdvertisement.AdvertFlags +if (intAdvertFlags and ONUSERLOGON) then + wscript.echo "ONUSERLOGON flag " & _ + "already set!" +else + wscript.echo "Setting ONUSERLOGON flag" + intAdvertFlags = intAdvertFlags or _ + ONUSERLOGON + objAdvertisement.AdvertFlags = intAdvertFlags + objAdvertisement.Put_ +end if + diff --git a/Chapter06/6-13_ModAdvert_AssignImmediately.vbs b/Chapter06/6-13_ModAdvert_AssignImmediately.vbs new file mode 100644 index 0000000..daf3335 --- /dev/null +++ b/Chapter06/6-13_ModAdvert_AssignImmediately.vbs @@ -0,0 +1,31 @@ +IMMEDIATE = 2^(5) +strSMSServer = + +strAdvertID = "LAB20016" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objAdvertisement = objSMS.Get _ + ("SMS_Advertisement.AdvertisementID='" & strAdvertID & "'") + +intAdvertFlags = objAdvertisement.AdvertFlags +if (intAdvertFlags and IMMEDIATE) then + wscript.echo "IMMEDIATE flag " & _ + "already set!" +else + wscript.echo "Setting IMMEDIATE flag" + intAdvertFlags = intAdvertFlags or _ + IMMEDIATE + objAdvertisement.AdvertFlags = intAdvertFlags + objAdvertisement.Put_ +end if diff --git a/Chapter06/6-14_ShowMandatoryAssignments.vbs b/Chapter06/6-14_ShowMandatoryAssignments.vbs new file mode 100644 index 0000000..fa61cf5 --- /dev/null +++ b/Chapter06/6-14_ShowMandatoryAssignments.vbs @@ -0,0 +1,108 @@ +IMMEDIATE = 2^(5) +ONUSERLOGON = 2^(9) +ONUSERLOGOFF = 2^(10) + +strSMSServer = + +strAdvertID = "LAB20015" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objAdvert=objSMS.Get _ + ("SMS_Advertisement.AdvertisementID='" & strAdvertID & "'") + +wscript.echo "Mandatory Assignment(s) for " & chr(34) & _ + objAdvert.AdvertisementName & " (" & strAdvertID & ")" & _ + chr(34) + +intAdvertFlags = objAdvert.AdvertFlags +if (intAdvertFlags and IMMEDIATE) then + wscript.echo "Event Assignment to run IMMEDIATELY." +end if +if (intAdvertFlags and ONUSERLOGON) then + wscript.echo "Event Assignment to run On User Logon." +end if +if (intAdvertFlags and ONUSERLOGOFF) then + wscript.echo "Event Assignment to run On User Logoff." +end if + +for each objSched in objAdvert.AssignedSchedule + 'for a 'quick and dirty', instead of the case statement + 'below, you could just display the information in the object + 'by using objSched.GetObjectText_ + 'wscript.echo objSched.GetObjectText_ + wscript.echo objSched.Path_.Class + select case objSched.Path_.Class + case "SMS_ST_NonRecurring" + strInfo = vbTAB & "Non-Recurring Assignment: " + strInfo = strInfo & "Occurs at " & _ + WMIDateStringToDate(objSched.StartTime) + if objSched.IsGMT then + strInfo = strInfo & " GMT" + end if + + case "SMS_ST_RecurInterval" + strInfo = vbTAB & "Recurring Interval Assignment: " + strInfo = strInfo & "Every " & objSched.DaySpan & _ + " days, " & objSched.MinuteSpan & " minutes, " + strInfo = strInfo & "beginning on " & _ + WMIDateStringToDate(objSched.StartTime) + if objSched.IsGMT then + strInfo = strInfo & " GMT" + end if + + case "SMS_ST_RecurMonthlyByDate" + strInfo = vbTAB & "Recurring Monthly By Date: " + strInfo = strInfo & "Occurs on the " & _ + objSched.MonthDay & " day, every " & _ + objSched.ForNumberOfMonths & " months, " + strInfo = strInfo & "beginning on " & _ + WMIDateStringToDate(objSched.StartTime) + if objSched.IsGMT then + strInfo = strInfo & " GMT" + end if + + case "SMS_ST_RecurMonthlyByWeekday" + strInfo = vbTAB & "Recurring Monthly By Weekday: " + strInfo = strInfo & "Occurs on the " & _ + objSched.Day & " day, every " & _ + objSched.ForNumberOfMonths & " months, " & _ + "for week order " & objSched.WeekOrder & "," + strInfo = strInfo & "beginning on " & _ + WMIDateStringToDate(objSched.StartTime) + if objSched.IsGMT then + strInfo = strInfo & " GMT" + end if + + case "SMS_ST_RecurWeekly" + strInfo = vbTAB & "Recurring Monthly By Weekday: " + strInfo = strInfo & "Occurs on the " & _ + objSched.Day & " day, every " & _ + objSched.ForNumberOfWeeks & " weeks, " + strInfo = strInfo & "beginning on " & _ + WMIDateStringToDate(objSched.StartTime) + if objSched.IsGMT then + strInfo = strInfo & " GMT" + end if + + end select + wscript.echo strInfo +next + +Function WMIDateStringToDate(dtmInstallDate) +WMIDateStringToDate = CDate(Mid(dtmInstallDate, 5, 2) & "/" & _ + Mid(dtmInstallDate, 7, 2) & "/" & Left(dtmInstallDate, 4) _ + & " " & Mid (dtmInstallDate, 9, 2) & ":" & _ + Mid(dtmInstallDate, 11, 2) & ":" & _ + Mid(dtmInstallDate, 13, 2)) +End Function diff --git a/Chapter06/6-15_ExpireAdvert.vbs b/Chapter06/6-15_ExpireAdvert.vbs new file mode 100644 index 0000000..c4ef5fe --- /dev/null +++ b/Chapter06/6-15_ExpireAdvert.vbs @@ -0,0 +1,43 @@ +strSMSServer = + +strAdvertID = "LAB20016" +'For advExpTime, 'Now()' is used to get the current +'date/time of the system. A properly fomatted date/time would +'just fine here also: e.g., "12/02/2006 12:59 AM" +' and in this example, we're adding 5 days to the current date +' to calculate the expire time +dtmExpireDateTime = dateadd("d",5,Now()) + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objAdvert=objSMS.Get _ + ("SMS_Advertisement.AdvertisementID='" & strAdvertID & "'") +objAdvert.ExpirationTime = ConvertToWMIDate(dtmExpireDateTime) +objAdvert.ExpirationTimeEnabled = True +'objAdvert.ExpirationTimeIsGMT = True 'if using GMT +objAdvert.Put_ + +Function ConvertToWMIDate(strDate) + 'Convert from a standard date time to wmi date + '4/18/2005 11:30:00 AM = 2005041811300.000000+*** + strYear = year(strDate):strMonth = month(strDate) + strDay = day(strDate):strHour = hour(strDate) + strMinute = minute(strDate) + 'Pad single digits with leading zero + if len(strmonth) = 1 then strMonth = "0" & strMonth + if len(strDay) = 1 then strDay = "0" & strDay + if len(strHour) = 1 then strHour = "0" & strHour + if len(strMinute) = 1 then strMinute = "0" & strMinute + ConvertToWMIDate = strYear & strMonth & strDay & strHour _ + & strMinute & "00.000000+***" +end function \ No newline at end of file diff --git a/Chapter06/6-16_ListAllAdvertsThatHaveExpireTimesEnabled.vbs b/Chapter06/6-16_ListAllAdvertsThatHaveExpireTimesEnabled.vbs new file mode 100644 index 0000000..c2898dc --- /dev/null +++ b/Chapter06/6-16_ListAllAdvertsThatHaveExpireTimesEnabled.vbs @@ -0,0 +1,50 @@ +strSMSServer = + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set colAdverts = objSMS.ExecQuery _ + ("Select * From SMS_Advertisement order by " & _ + " AdvertisementName") +For Each objAdvert In colAdverts + strExpireTime = GetExpirationDateTimeString _ + (objAdvert.AdvertisementID) + if (not strExpireTime = "") then + wscript.echo objAdvert.AdvertisementID & vbTAB & _ + objAdvert.AdvertisementName & vbTAB & strExpireTime + end if +Next + +Function GetExpirationDateTimeString(strAdvertID) + Set objAdvert=objSMS.Get _ + ("SMS_Advertisement.AdvertisementID='" & _ + strAdvertID & "'") + if objAdvert.ExpirationTimeEnabled = True then + GetExpirationDateTimeString = _ + WMIDateStringToDate(objAdvert.ExpirationTime) + if (objAdvert.ExpirationTimeIsGMT) Then + GetExpirationDateTimeString = _ + GetExpirationDateTimeString & " GMT" + end if + end if +End Function + +'Utility function to convert WMI Date string to a real date +Function WMIDateStringToDate(dtmInstallDate) + '4/12/2005 3:46:04 AM = 20050412034604.000000-000 + WMIDateStringToDate = CDate(Mid(dtmInstallDate, 5, 2) & _ + "/" & Mid(dtmInstallDate, 7, 2) & "/" & _ + Left(dtmInstallDate, 4) & " " & _ + Mid (dtmInstallDate, 9, 2) & ":" & _ + Mid(dtmInstallDate, 11, 2) & ":" & _ + Mid(dtmInstallDate,13, 2)) +End Function \ No newline at end of file diff --git a/Chapter06/6-17_ChangeAdvertPriority.vbs b/Chapter06/6-17_ChangeAdvertPriority.vbs new file mode 100644 index 0000000..3813133 --- /dev/null +++ b/Chapter06/6-17_ChangeAdvertPriority.vbs @@ -0,0 +1,23 @@ +strSMSServer = + +strAdvertID = "LAB20016" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objAdvert=objSMS.Get _ + ("SMS_Advertisement.AdvertisementID='" & strAdvertID & "'") +objAdvert.Priority = 1 +objAdvert.Put_ +'1=high +'2=normal +'3=low \ No newline at end of file diff --git a/Chapter06/6-18_RemoteClientFlagsFromDP.vbs b/Chapter06/6-18_RemoteClientFlagsFromDP.vbs new file mode 100644 index 0000000..0da7a40 --- /dev/null +++ b/Chapter06/6-18_RemoteClientFlagsFromDP.vbs @@ -0,0 +1,25 @@ +RUN_FROM_LOCAL_DISPPOINT = 2^(3) +RUN_FROM_REMOTE_DISPPOINT = 2^(7) + +strSMSServer = + +strAdvertID = "LAB20016" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objAdvertisement = objSMS.Get _ + ("SMS_Advertisement.AdvertisementID='" & strAdvertID & "'") + +objAdvertisement.RemoteClientFlags = _ + RUN_FROM_LOCAL_DISPPOINT + RUN_FROM_REMOTE_DISPPOINT +objAdvertisement.Put_ diff --git a/Chapter06/6-19_RemoteClientFlagsDLFromDP.vbs b/Chapter06/6-19_RemoteClientFlagsDLFromDP.vbs new file mode 100644 index 0000000..90fb745 --- /dev/null +++ b/Chapter06/6-19_RemoteClientFlagsDLFromDP.vbs @@ -0,0 +1,26 @@ +DOWNLOAD_FROM_LOCAL_DISPPOINT = 2^(4) +DOWNLOAD_FROM_REMOTE_DISPPOINT = 2^(6) + +strSMSServer = + +strAdvertID = "LAB20016" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objAdvertisement = objSMS.Get _ + ("SMS_Advertisement.AdvertisementID='" & strAdvertID & "'") + +objAdvertisement.RemoteClientFlags = _ + DOWNLOAD_FROM_LOCAL_DISPPOINT + _ + DOWNLOAD_FROM_REMOTE_DISPPOINT +objAdvertisement.Put_ diff --git a/Chapter06/6-1_CreateAdvert.vbs b/Chapter06/6-1_CreateAdvert.vbs new file mode 100644 index 0000000..fdfb2e0 --- /dev/null +++ b/Chapter06/6-1_CreateAdvert.vbs @@ -0,0 +1,24 @@ +strSMSServer = +advName = "Microsoft .NET Framework 1.1 SP1" +advCollection = "SMS000GS" +advPackageID = "LAB0000A" +advProgramName = "NET Framework 1.1 SP1" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set newAdvert = objSMS.Get("SMS_Advertisement").SpawnInstance_() +newAdvert.AdvertisementName = advName +newAdvert.CollectionID = advCollection +newAdvert.PackageID = advPackageID +newAdvert.ProgramName = advProgramName +newAdvert.Put_ diff --git a/Chapter06/6-20_ShowAdvertsConfiguredtoDandE_RemoteClientFlags.vbs b/Chapter06/6-20_ShowAdvertsConfiguredtoDandE_RemoteClientFlags.vbs new file mode 100644 index 0000000..9537064 --- /dev/null +++ b/Chapter06/6-20_ShowAdvertsConfiguredtoDandE_RemoteClientFlags.vbs @@ -0,0 +1,60 @@ +RUN_FROM_LOCAL_DISPPOINT = 2^(3) +DOWNLOAD_FROM_LOCAL_DISPPOINT = 2^(4) +DONT_RUN_NO_LOCAL_DISPPOINT = 2^(5) +DOWNLOAD_FROM_REMOTE_DISPPOINT = 2^(6) +RUN_FROM_REMOTE_DISPPOINT = 2^(7) + +RunFromLocalDP_DownloadIfRemoteDP = _ + RUN_FROM_LOCAL_DISPPOINT + DOWNLOAD_FROM_REMOTE_DISPPOINT +DownloadFromLocal_DontRunNoLocal = _ + DOWNLOAD_FROM_LOCAL_DISPPOINT + DONT_RUN_NO_LOCAL_DISPPOINT +DownloadFromLocalDP_DownloadIfRemoteDP = _ + DOWNLOAD_FROM_LOCAL_DISPPOINT + _ + DOWNLOAD_FROM_REMOTE_DISPPOINT + + +strSMSServer = + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set colAdverts = objSMS.ExecQuery _ + ("Select * From SMS_Advertisement where " & _ + "RemoteClientFlags = " & _ + RunFromLocalDP_DownloadIfRemoteDP & _ + " or RemoteClientFlags = " & _ + DownloadFromLocal_DontRunNoLocal & _ + " or RemoteClientFlags = " & _ + DownloadFromLocalDP_DownloadIfRemoteDP & " order by " & _ + " AdvertisementName") + +For Each objAdvert In colAdverts + Select Case objAdvert.RemoteclientFlags + + Case RunFromLocalDP_DownloadIfRemoteDP + wscript.echo objAdvert.AdvertisementName & vbTAB & _ + "(RunFromLocalDP_DownloadIfRemoteDP)" + + Case DownloadFromLocal_DontRunNoLocal + wscript.echo objAdvert.AdvertisementName & vbTAB & _ + "(DownloadFromLocal_DontRunNoLocal)" + + Case DownloadFromLocalDP_DownloadIfRemoteDP + wscript.echo objAdvert.AdvertisementName & vbTAB & _ + "(DownloadFromLocalDP_DownloadIfRemoteDP)" + + Case Else + 'neither remote or local are configured to + ' download from DP + End Select +Next + diff --git a/Chapter06/6-21_CreateAdvertFolder.vbs b/Chapter06/6-21_CreateAdvertFolder.vbs new file mode 100644 index 0000000..12bc373 --- /dev/null +++ b/Chapter06/6-21_CreateAdvertFolder.vbs @@ -0,0 +1,30 @@ +strSMSServer = + +strNewFolderName = "Security Patches" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set newFolder = objSMS.Get("SMS_ObjectContainerNode") _ + .SpawnInstance_() +newFolder.Name = strNewFolderName +newFolder.ObjectType = 3 'advertisement +newFolder.ParentContainerNodeId = 0 +newFolder.Put_ + + +'Property value Object type +'2 Package +'3 Advertisement +'7 Query +'8 Report +'9 Software Metering diff --git a/Chapter06/6-22_MoveAdvertsBetweenFolders.vbs b/Chapter06/6-22_MoveAdvertsBetweenFolders.vbs new file mode 100644 index 0000000..898bbf3 --- /dev/null +++ b/Chapter06/6-22_MoveAdvertsBetweenFolders.vbs @@ -0,0 +1,26 @@ +strSMSServer = + +strSMSSiteCode = "LAB" +strAdvertIDs = "LAB20013,LAB20014" + +'to move more than one, separate with commas +intSourceFolder=0 'Source Folder (root node in this case) +intDestFolder=7 'Destination Folder +intObjectType=3 '3=Advertisement for type of object + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objFolder = objSMS.Get("SMS_ObjectContainerItem") +arrAdvertIDs = split(strAdvertIDs, ",") +retval = objFolder.MoveMembers _ +(arrAdvertIDs, intSourceFolder, intDestFolder, intObjectType) diff --git a/Chapter06/6-23_DisableProgram_Advert.vbs b/Chapter06/6-23_DisableProgram_Advert.vbs new file mode 100644 index 0000000..1973485 --- /dev/null +++ b/Chapter06/6-23_DisableProgram_Advert.vbs @@ -0,0 +1,32 @@ +strSMSServer = + +strPackageID = "LAB00006" +strProgramName = "Microsoft Updates Tool" +DISABLE_PROGRAM = 2^(12) + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objProgram=objSMS.Get("SMS_Program.PackageID='" & _ + strPackageID & "',ProgramName='" & strProgramName & "'") + +intProgramFlags = objProgram.ProgramFlags + +if (intProgramFlags and DISABLE_PROGRAM) then + wscript.echo "Disable Program Flag already set!" +else + wscript.echo "Disabling program now." + intProgramFlags = intProgramFlags or DISABLE_PROGRAM + objProgram.ProgramFlags = intProgramFlags + objProgram.Put_ +end if + diff --git a/Chapter06/6-24_ShowAdvertStatus.vbs b/Chapter06/6-24_ShowAdvertStatus.vbs new file mode 100644 index 0000000..d67a1dd --- /dev/null +++ b/Chapter06/6-24_ShowAdvertStatus.vbs @@ -0,0 +1,49 @@ +CONST SINCE_ADVERTISED = "0001128000080008" + +strSMSServer = + +strAdvertID = "LAB20014" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set colAdvertStatus = objSMS.ExecQuery _ + ("Select * From SMS_AdvertisementStatusSummarizer where" & _ + " AdvertisementID = '" & strAdvertID & _ + "' and DisplaySchedule = '" & SINCE_ADVERTISED & "'") + for each objAS in colAdvertStatus + wscript.echo objAS.SiteCode & vbTAB & _ + objAS.AdvertisementsReceived & vbTAB & _ + objAS.AdvertisementsFailed & vbTAB & _ + objAS.ProgramsStarted & vbTAB & _ + objAS.ProgramsFailed & vbTAB & _ + objAS.ProgramsSucceeded & vbTAB & _ + objAS.ProgramsFailedMIF & vbTAB & _ + objAS.ProgramsSucceededMIF + next + + +'TABLE -- Tally Intervals -- from the SDK +' CONST SINCE_ADVERTISED = "0001128000080008" +' CONST SINCE12_00_AM = "0001128000100008" +' CONST SINCE06_00AM = "00C1128000100008" +' CONST SINCE12_00_PM = "0181128000100008" +' CONST SINCE06_00_PM = "0241128000100008" +' CONST SINCE_SUNDAY = "0001128000192000" +' CONST SINCE_MONDAY = "00011280001A2000" +' CONST SINCE_TUESDAY = "00011280001B2000" +' CONST SINCE_WEDNESDAY = "00011280001C2000" +' CONST SINCE_THURSDAY = "00011280001D2000" +' CONST SINCE_FRIDAY = "00011280001E2000" +' CONST SINCE_SATURDAY = "00011280001F2000" +' CONST SINCE_1ST_OF_MONTH = "000A470000284400" +' CONST SINCE_15TH_OF_MONTH = "000A4700002BC400" \ No newline at end of file diff --git a/Chapter06/6-2_DeleteAdvert.vbs b/Chapter06/6-2_DeleteAdvert.vbs new file mode 100644 index 0000000..7c916cc --- /dev/null +++ b/Chapter06/6-2_DeleteAdvert.vbs @@ -0,0 +1,20 @@ +strSMSServer = + +strAdvertID = "LAB20007" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objAdvert=objSMS.Get _ + ("SMS_Advertisement.AdvertisementID='" & strAdvertID & "'") +wscript.echo "Deleting " & objAdvert.AdvertisementName +objAdvert.Delete_ diff --git a/Chapter06/6-3_DeleteMultipleAdverts_SamePackage.vbs b/Chapter06/6-3_DeleteMultipleAdverts_SamePackage.vbs new file mode 100644 index 0000000..36f4121 --- /dev/null +++ b/Chapter06/6-3_DeleteMultipleAdverts_SamePackage.vbs @@ -0,0 +1,22 @@ +strSMSServer = +strPackageID = "LAB00002" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set colAdverts = objSMS.ExecQuery("Select * From SMS_Advertisement " & _ + "WHERE PackageID='" & strPackageID & "'") +For Each objAdvert In colAdverts + wscript.echo "Deleting " & objAdvert.AdvertisementName + objAdvert.Delete_ +Next + diff --git a/Chapter06/6-4_ListAdverts.vbs b/Chapter06/6-4_ListAdverts.vbs new file mode 100644 index 0000000..2d4b36a --- /dev/null +++ b/Chapter06/6-4_ListAdverts.vbs @@ -0,0 +1,21 @@ +strSMSServer = + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set colAdverts = objSMS.ExecQuery _ + ("Select * From SMS_Advertisement order by " & _ + " AdvertisementName") +For Each objAdvert In colAdverts + wscript.echo objAdvert.AdvertisementName & vbTAB & _ + objAdvert.PresentTime & objAdvert.AssignedSchedule +Next diff --git a/Chapter06/6-5_ModifyAdvert.vbs b/Chapter06/6-5_ModifyAdvert.vbs new file mode 100644 index 0000000..92afda4 --- /dev/null +++ b/Chapter06/6-5_ModifyAdvert.vbs @@ -0,0 +1,23 @@ +strSMSServer = + +strAdvertID = "LAB20015" +strNewPackageID = "LAB00006" +strNewProgramName = "Microsoft Updates Tool" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objAdvert=objSMS.Get _ + ("SMS_Advertisement.AdvertisementID='" & strAdvertID & "'") +objAdvert.PackageID = strNewPackageID +objAdvert.ProgramName = strNewProgramName +objAdvert.Put_ diff --git a/Chapter06/6-6_ModifyAdvert.vbs b/Chapter06/6-6_ModifyAdvert.vbs new file mode 100644 index 0000000..25da42f --- /dev/null +++ b/Chapter06/6-6_ModifyAdvert.vbs @@ -0,0 +1,21 @@ +strSMSServer = + +strAdvertID = "LAB20015" +strNewCollectionID = "LAB00011" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objAdvert=objSMS.Get _ + ("SMS_Advertisement.AdvertisementID='" & strAdvertID & "'") +objAdvert.CollectionID = strNewCollectionID +objAdvert.Put_ diff --git a/Chapter06/6-7_ModAdvert_Voluntary.vbs b/Chapter06/6-7_ModAdvert_Voluntary.vbs new file mode 100644 index 0000000..a953f8e --- /dev/null +++ b/Chapter06/6-7_ModAdvert_Voluntary.vbs @@ -0,0 +1,24 @@ +NO_DISPLAY = 2^(25) + +strSMSServer = + +strAdvertID = "LAB20153" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set objAdvertisement = objSMS.Get _ + ("SMS_Advertisement.AdvertisementID='" & strAdvertID & "'") + +objAdvertisement.AdvertFlags = objAdvertisement.AdvertFlags _ + and not NO_DISPLAY +objAdvertisement.Put_ diff --git a/Chapter06/6-8_ModAdvert_Mandatory.vbs b/Chapter06/6-8_ModAdvert_Mandatory.vbs new file mode 100644 index 0000000..c8256cd --- /dev/null +++ b/Chapter06/6-8_ModAdvert_Mandatory.vbs @@ -0,0 +1,54 @@ +strSMSServer = + +strAdvertID = "LAB20016" +'For advAssignedSchedule, 'Now()' is used to get the current +'date/time of the system. A properly fomatted date/time would +'just fine here also: e.g., "12/02/2006 12:59 AM" +advAssignedSchedule = Now() + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +'create a non-recurring schedule token +Set instToken = objSMS.Get("SMS_ST_NonRecurring"). _ + SpawnInstance_() +instToken.StartTime = ConvertToWMIDate(advAssignedSchedule) +retval = AddSchedToken(instToken, strAdvertID) + +Function AddSchedToken(objSchedToken, strAdvertID) + 'enlarge the current schedule array by 1 + Set objAdvert=objSMS.Get _ + ("SMS_Advertisement.AdvertisementID='" & strAdvertID & "'") + advertArray = objAdvert.AssignedSchedule + onemore = ubound(advertArray) + 1 + redim preserve advertArray(onemore) + objAdvert.AssignedSchedule = advertArray + 'add the new assignment + objAdvert.AssignedSchedule(onemore) = objSchedToken + objadvert.AssignedScheduleEnabled = True + AddSchedToken = objAdvert.Put_ +End Function + +Function ConvertToWMIDate(strDate) + 'Convert from a standard date time to wmi date + '4/18/2005 11:30:00 AM = 2005041811300.000000+*** + strYear = year(strDate):strMonth = month(strDate) + strDay = day(strDate):strHour = hour(strDate) + strMinute = minute(strDate) + 'Pad single digits with leading zero + if len(strmonth) = 1 then strMonth = "0" & strMonth + if len(strDay) = 1 then strDay = "0" & strDay + if len(strHour) = 1 then strHour = "0" & strHour + if len(strMinute) = 1 then strMinute = "0" & strMinute + ConvertToWMIDate = strYear & strMonth & strDay & strHour _ + & strMinute & "00.000000+***" +end function \ No newline at end of file diff --git a/Chapter06/6-9_ModAdvert_RecurringSMS_ST_RecurInterval.vbs b/Chapter06/6-9_ModAdvert_RecurringSMS_ST_RecurInterval.vbs new file mode 100644 index 0000000..727d1e2 --- /dev/null +++ b/Chapter06/6-9_ModAdvert_RecurringSMS_ST_RecurInterval.vbs @@ -0,0 +1,59 @@ +strSMSServer = + +strAdvertID = "LAB20016" +'"Occurs every 10 minutes beginning now()" +'For advStartTime, 'Now()' is used to get the current +'date/time of the system. A properly fomatted date/time would +'just fine here also: e.g., "12/02/2006 12:59 AM" +advStartTime = Now() + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +'''''''''''''Schedule Token Information +'Create a new instance of SMS_ST_RecurInterval +Set advNewRecurToken = objSMS.Get("SMS_ST_RecurInterval"). _ + SpawnInstance_() +advNewRecurToken.MinuteSpan=10 +advNewRecurToken.StartTime = ConvertToWMIDate(advStartTime) +'''''''''''''END Schedule Token Information + +retval = AddSchedToken(advNewRecurToken,strAdvertID) + +Function AddSchedToken(objSchedToken, strAdvertID) + 'enlarge the current schedule array by 1 + Set objAdvert=objSMS.Get _ + ("SMS_Advertisement.AdvertisementID='" & strAdvertID & "'") + advertArray = objAdvert.AssignedSchedule + onemore = ubound(advertArray) + 1 + redim preserve advertArray(onemore) + objAdvert.AssignedSchedule = advertArray + 'add the new assignment + objAdvert.AssignedSchedule(onemore) = objSchedToken + objadvert.AssignedScheduleEnabled = True + AddSchedToken = objAdvert.Put_ +End Function + +Function ConvertToWMIDate(strDate) + 'Convert from a standard date time to wmi date + '4/18/2005 11:30:00 AM = 2005041811300.000000+*** + strYear = year(strDate):strMonth = month(strDate) + strDay = day(strDate):strHour = hour(strDate) + strMinute = minute(strDate) + 'Pad single digits with leading zero + if len(strmonth) = 1 then strMonth = "0" & strMonth + if len(strDay) = 1 then strDay = "0" & strDay + if len(strHour) = 1 then strHour = "0" & strHour + if len(strMinute) = 1 then strMinute = "0" & strMinute + ConvertToWMIDate = strYear & strMonth & strDay & strHour _ + & strMinute & "00.000000+***" +end function diff --git a/Chapter06/6-Bonus_ShowAdvertAssignmentInfo.vbs b/Chapter06/6-Bonus_ShowAdvertAssignmentInfo.vbs new file mode 100644 index 0000000..ea12e93 --- /dev/null +++ b/Chapter06/6-Bonus_ShowAdvertAssignmentInfo.vbs @@ -0,0 +1,33 @@ +on error resume next +strSMSServer = + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + strSMSSiteCode = Loc.Sitecode + end if +Next + +Set colCollections = objSMS.ExecQuery _ +("select * from SMS_Collection order by Name") +For each objCollection in colCollections + wscript.echo objCollection.Name & vbTAB & _ + GetRecurSchedule(objCollection.CollectionID) +next + +Function GetRecurSchedule(strCollID) + Set objCollection = objSMS.Get _ + ("SMS_Collection.CollectionID='" & strCollID & "'") + if objCollection.RefreshType = 1 then + GetRecurSchedule = "Manual Refresh" + else + for each objSched in objCollection.RefreshSchedule + GetRecurSchedule = objSched.GetObjectText_ + next + end if +End Function \ No newline at end of file diff --git a/Chapter06/RemoteClientflags.txt b/Chapter06/RemoteClientflags.txt new file mode 100644 index 0000000..74656d4 --- /dev/null +++ b/Chapter06/RemoteClientflags.txt @@ -0,0 +1,18 @@ +RemoteClientFlags + +When a distribution point is available locally +A Run program from distribution point +B Download program from distribution point + +When no distribution point is available locally +C do not run program +D download program from a remote distribution point +E run program from a remote distribution point + + +default: +AC = 40 +AD = 72 +AE = 136 +BC = 48 +BD = 80 diff --git a/Chapter07/7-10_DisplayMeteredFileUsageSummaryData.vbs b/Chapter07/7-10_DisplayMeteredFileUsageSummaryData.vbs new file mode 100644 index 0000000..0ea54f3 --- /dev/null +++ b/Chapter07/7-10_DisplayMeteredFileUsageSummaryData.vbs @@ -0,0 +1,67 @@ +strSMSServer = + +intDays = 10 +strProductName = "sol" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +strWQL = "SELECT SMS_MeteredFiles.ProductName, " & _ + "SMS_FileUsageSummary.DistinctUserCount, " & _ + "SMS_FileUsageSummary.IntervalStart, " & _ + "SMS_FileUsageSummary.IntervalWidth, " & _ + "SMS_FileUsageSummary.SiteCode " & _ + "FROM SMS_MeteredFiles INNER JOIN SMS_FileUsageSummary " & _ + "ON SMS_MeteredFiles.MeteredFileID = " & _ + "SMS_FileUsageSummary.FileID WHERE " & _ + "datediff(day,SMS_FileUsageSummary.IntervalStart, getdate()) " & _ + "<= " & intDays & " AND " & _ + "(SMS_FileUsageSummary.IntervalWidth = 15) AND " & _ + "(SMS_MeteredFiles.ProductName = '" & strProductName & "')" + +wscript.echo "Product Name" & vbTAB & "Metered Interval" & vbTAB & _ + "Distinct Users" & vbTAB & "Site Code" +Set colMTRResults = objSMS.ExecQuery(strWQL) +for each objMTRResult in colMTRResults + wscript.echo objMTRResult.SMS_MeteredFiles.ProductName & _ + vbTAB & WMIDateStringToDate(objMTRResult. _ + SMS_FileUsageSummary.IntervalStart) & _ + vbTAB & objMTRResult.SMS_FileUsageSummary.DistinctUserCount & _ + vbTAB & objMTRResult.SMS_FileUsageSummary.SiteCode + if intPeak < objMTRResult.SMS_FileUsageSummary.DistinctUserCount then + intPeak = objMTRResult.SMS_FileUsageSummary.DistinctUserCount + strPeakInfo = WMIDateStringToDate(objMTRResult. _ + SMS_FileUsageSummary.IntervalStart) & vbTAB & _ + objMTRResult.SMS_FileUsageSummary.DistinctUserCount _ + & vbTAB & objMTRResult.SMS_FileUsageSummary.SiteCode _ + & vbCRLF + elseif intPeak = _ + objMTRResult.SMS_FileUsageSummary.DistinctUserCount then + strPeakInfo = strPeakInfo & WMIDateStringToDate(objMTRResult. _ + SMS_FileUsageSummary.IntervalStart) & vbTAB & _ + objMTRResult.SMS_FileUsageSummary.DistinctUserCount _ + & vbTAB & objMTRResult.SMS_FileUsageSummary.SiteCode _ + & vbCRLF + end if +next + +wscript.echo vbCRLF & vbCRLF +wscript.echo "Peak concurrentusage over the past " & intDays & _ + " days of metering data:" & vbCRLF & strPeakInfo + +Function WMIDateStringToDate(dtmInstallDate) + WMIDateStringToDate = CDate(Mid(dtmInstallDate, 5, 2) & "/" & _ + Mid(dtmInstallDate, 7, 2) & "/" & Left(dtmInstallDate, 4) _ + & " " & Mid (dtmInstallDate, 9, 2) & ":" & _ + Mid(dtmInstallDate, 11, 2) & ":" & Mid(dtmInstallDate, _ + 13, 2)) +End Function + diff --git a/Chapter07/7-1_CreatingMeteringRule.vbs b/Chapter07/7-1_CreatingMeteringRule.vbs new file mode 100644 index 0000000..a2c33d9 --- /dev/null +++ b/Chapter07/7-1_CreatingMeteringRule.vbs @@ -0,0 +1,30 @@ +strSMSServer = + +strProdcutName = "WinZip" +strFileName = "WinZip32.exe" +strFileVersion = "*" +strLanguageID = 65535 '65535 = 'any language' + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set newMTRRule = _ + objSMS.Get("SMS_MeteredProductRule").SpawnInstance_() + +newMTRRule.ProductName = strProdcutName +newMTRRule.FileName = strFileName +newMTRRule.FileVersion = strFileVersion +newMTRRule.LanguageID = strLanguageID +newMTRRule.SiteCode = ucase(strSMSSiteCode) +newMTRRule.ApplyToChildSites = TRUE +newMTRRule.Enabled = TRUE +newMTRRule.Put_ + diff --git a/Chapter07/7-2_DeletingASoftwareMeteringRule.vbs b/Chapter07/7-2_DeletingASoftwareMeteringRule.vbs new file mode 100644 index 0000000..2290062 --- /dev/null +++ b/Chapter07/7-2_DeletingASoftwareMeteringRule.vbs @@ -0,0 +1,22 @@ +strSMSServer = + +strProductName = "WinZip" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set colMTRRules = objSMS.ExecQuery _ + ("Select * From SMS_MeteredProductRule where " & _ + "ProductName = '" & strProductName & "'") +For Each objMTRRule In colMTRRules + wscript.echo "Deleting " & objMTRRule.ProductName + objMTRRule.Delete_ +Next \ No newline at end of file diff --git a/Chapter07/7-3_ViewingAllSoftwareMeteringRules.vbs b/Chapter07/7-3_ViewingAllSoftwareMeteringRules.vbs new file mode 100644 index 0000000..d31f0e2 --- /dev/null +++ b/Chapter07/7-3_ViewingAllSoftwareMeteringRules.vbs @@ -0,0 +1,23 @@ +strSMSServer = + + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set colMTRs = objSMS.ExecQuery _ + ("Select * From SMS_MeteredProductRule order by " & _ + " ProductName") +for each objMTRRule in colMTRS + wscript.echo objMTRRule.ProductName & vbTAB & _ + objMTRRule.FileName & vbTAB & objMTRRule.FileVersion & _ + vbTAB & objMTRRule.SiteCode & vbTAB & _ + objMTRRule.ApplyToChildSites & vbTAB & objMTRRule.Enabled +next \ No newline at end of file diff --git a/Chapter07/7-4_ModifyMeteringRule.vbs b/Chapter07/7-4_ModifyMeteringRule.vbs new file mode 100644 index 0000000..17073e2 --- /dev/null +++ b/Chapter07/7-4_ModifyMeteringRule.vbs @@ -0,0 +1,23 @@ +strSMSServer = + +strProductName = "Sol" +strNewProductName = "Solitaire" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set colMTRs = objSMS.ExecQuery _ + ("Select * From SMS_MeteredProductRule where " & _ + "ProductName = '" & strProductName & "'") +for each objMTRRule in colMTRS + objMTRRule.ProductName = strNewProductName + objMTRRule.Put_ +next diff --git a/Chapter07/7-5_DisableMeteringRule.vbs b/Chapter07/7-5_DisableMeteringRule.vbs new file mode 100644 index 0000000..ebeb98f --- /dev/null +++ b/Chapter07/7-5_DisableMeteringRule.vbs @@ -0,0 +1,22 @@ +strSMSServer = + +strProductName = "Sol" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set colMTRs = objSMS.ExecQuery _ + ("Select * From SMS_MeteredProductRule where " & _ + "ProductName = '" & strProductName & "'") +for each objMTRRule in colMTRS + objMTRRule.Enabled = False + objMTRRule.Put_ +next \ No newline at end of file diff --git a/Chapter07/7-6_EnableMeteringRule.vbs b/Chapter07/7-6_EnableMeteringRule.vbs new file mode 100644 index 0000000..6ab3c60 --- /dev/null +++ b/Chapter07/7-6_EnableMeteringRule.vbs @@ -0,0 +1,28 @@ +strSMSServer = + +strProductName = "Sol" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set colMTRs = objSMS.ExecQuery _ + ("Select * From SMS_MeteredProductRule where " & _ + "ProductName = '" & strProductName & "'") +for each objMTRRule in colMTRS + if not (objMTRRule.Enabled) then + wscript.echo "Enabling Rule " & strProductName + objMTRRule.Enabled = True + objMTRRule.Put_ + else + wscript.echo "Rule " & strProductName & " aready " & _ + "enabled!" + end if +next \ No newline at end of file diff --git a/Chapter07/7-7_CreateMeteringFolder.vbs b/Chapter07/7-7_CreateMeteringFolder.vbs new file mode 100644 index 0000000..e16cf81 --- /dev/null +++ b/Chapter07/7-7_CreateMeteringFolder.vbs @@ -0,0 +1,28 @@ +strSMSServer = + +strNewFolderName = "InBit Software" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set newFolder = objSMS.Get("SMS_ObjectContainerNode") _ + .SpawnInstance_() +newFolder.Name = strNewFolderName +newFolder.ObjectType = 9 'metering Folder +newFolder.ParentContainerNodeId = 0 'root folder +newFolder.Put_ + +'Property value Object type +'2 Package +'3 Advertisement +'7 Query +'8 Report +'9 Software Metering diff --git a/Chapter07/7-8_MoveMeteringRulesBetweenFolders.vbs b/Chapter07/7-8_MoveMeteringRulesBetweenFolders.vbs new file mode 100644 index 0000000..9556907 --- /dev/null +++ b/Chapter07/7-8_MoveMeteringRulesBetweenFolders.vbs @@ -0,0 +1,23 @@ +strSMSServer = + +strMeteringIDs = "LAB00008,LAB00009" +'to move more than one, separate with commas +intSourceFolder = 0 'Source Folder (root node in this case) +intDestFolder = 8 'Destination Folder +intObjectType = 9 '9=Metering Rule for type of object + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set objFolder = objSMS.Get("SMS_ObjectContainerItem") +arrMeteringIDs = split(strMeteringIDs, ",") +retval = objFolder.MoveMembers _ +(arrMeteringIDs, intSourceFolder, intDestFolder , intObjectType) diff --git a/Chapter07/7-9_DisplayMonthlySummaryData.vbs b/Chapter07/7-9_DisplayMonthlySummaryData.vbs new file mode 100644 index 0000000..7140d3d --- /dev/null +++ b/Chapter07/7-9_DisplayMonthlySummaryData.vbs @@ -0,0 +1,54 @@ +strSMSServer = + +strUserName = "ramseyg" +intDays = 180 + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +strWQL = "SELECT SMS_MeteredFiles.ProductName, " & _ + "SMS_MeteredUser.FullName, SMS_MonthlyUsageSummary.UsageCount, " & _ + "SMS_MonthlyUsageSummary.TSUsageCount, " & _ + "SMS_MonthlyUsageSummary.LastUsage, SMS_R_System.Name " & _ + "FROM SMS_MonthlyUsageSummary INNER JOIN " & _ + "SMS_R_System ON SMS_MonthlyUsageSummary.ResourceID = " & _ + "SMS_R_System.ResourceID INNER JOIN " & _ + "SMS_MeteredUser ON SMS_MonthlyUsageSummary.MeteredUserID = " & _ + "SMS_MeteredUser.MeteredUserID INNER JOIN " & _ + "SMS_MeteredFiles ON SMS_MonthlyUsageSummary.FileID = " & _ + "SMS_MeteredFiles.MeteredFileID " & _ + "WHERE (SMS_MeteredUser.UserName = '" & strUserName & "') " & _ + "and datediff" & _ + "(day, SMS_MonthlyUsageSummary.LastUsage, getdate()) <= " & _ + intDays & "ORDER BY SMS_MonthlyUsageSummary.LastUsage" + +wscript.echo "Product Name" & vbTAB & "Domain\UserName" & vbTAB & _ + "Usage Count" & vbTAB & "TSUsage Count" & vbTAB & _ + "ComputerName" & vbTAB & "LastUsageRecordedForMonth" + +Set colMTRResults = objSMS.ExecQuery(strWQL) +for each objMTRResult in colMTRResults + wscript.echo objMTRResult.SMS_MeteredFiles.ProductName & vbTAB & _ + objMTRResult.SMS_MeteredUser.FullName & vbTAB & _ + objMTRResult.SMS_MonthlyUsageSummary.UsageCount & vbTAB & _ + objMTRResult.SMS_MonthlyUsageSummary.TSUsageCount & vbTAB & _ + objMTRResult.SMS_R_System.Name & vbTAB & _ + WMIDateStringToDate(objMTRResult.SMS_MonthlyUsageSummary.LastUsage) +next + +Function WMIDateStringToDate(dtmInstallDate) + WMIDateStringToDate = CDate(Mid(dtmInstallDate, 5, 2) & "/" & _ + Mid(dtmInstallDate, 7, 2) & "/" & Left(dtmInstallDate, 4) _ + & " " & Mid (dtmInstallDate, 9, 2) & ":" & _ + Mid(dtmInstallDate, 11, 2) & ":" & Mid(dtmInstallDate, _ + 13, 2)) +End Function + diff --git a/Chapter08/8-1_ListAllReports.vbs b/Chapter08/8-1_ListAllReports.vbs new file mode 100644 index 0000000..9c0c25a --- /dev/null +++ b/Chapter08/8-1_ListAllReports.vbs @@ -0,0 +1,30 @@ +strSMSServer = + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set colReports = objSMS.ExecQuery _ + ("Select * From SMS_Report order by " & _ + " ReportID") + +For Each objReport In colReports + DisplayRptInfo(objReport.ReportID) +Next + +Sub DisplayRptInfo(intReportID) + 'SQLQuery is a lazy property, so we need to use the + 'Get method to retrieve the information + Set objRpt = objSMS.Get("SMS_Report.ReportID=" & intReportID) + wscript.echo objRpt.ReportID & vbTAB & objRpt.Name & _ + vbTAB & objRpt.DrillThroughReportID & _ + objRpt.SecurityKey & vbTAB & objRpt.MachineDetail & _ + vbCRLF & vbCRLF & objRpt.SQLQuery & vbCRLF & vbCRLF +End Sub diff --git a/Chapter08/8-2_CreateReportFolder.vbs b/Chapter08/8-2_CreateReportFolder.vbs new file mode 100644 index 0000000..6987d6e --- /dev/null +++ b/Chapter08/8-2_CreateReportFolder.vbs @@ -0,0 +1,26 @@ +strSMSServer = + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set newFolder = objSMS.Get("SMS_ObjectContainerNode") _ + .SpawnInstance_() +newFolder.Name = strNewFolderName +newFolder.ObjectType = 8 'Report +newFolder.ParentContainerNodeId = 0 +newFolder.Put_ + +'Property value Object type +'2 Package +'3 Advertisement +'7 Query +'8 Report +'9 Software Metering diff --git a/Chapter08/8-3_MoveReportssBetweenFolders.vbs b/Chapter08/8-3_MoveReportssBetweenFolders.vbs new file mode 100644 index 0000000..13fd3a6 --- /dev/null +++ b/Chapter08/8-3_MoveReportssBetweenFolders.vbs @@ -0,0 +1,24 @@ +strSMSServer = + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next +'Use the "SecuirtyKey" ID as the Report ID +strReportIDs = "LAB00001,LAB00002,LAB00004,LAB00005,LAB00023" +'to move more than one, separate with commas +intSourceFolder=0 'Source Folder (root node in this case) +intDestFolder=9 'Destination Folder +intObjectType=8 '8=Report for type of object + +Set objFolder = objSMS.Get("SMS_ObjectContainerItem") +arrReportIDs = split(strReportIDs, ",") +retval = objFolder.MoveMembers _ +(arrReportIDs, intSourceFolder, intDestFolder , intObjectType) +wscript.echo retval diff --git a/Chapter09/9-10_ListAllCollLimitQueries.vbs b/Chapter09/9-10_ListAllCollLimitQueries.vbs new file mode 100644 index 0000000..9c8e178 --- /dev/null +++ b/Chapter09/9-10_ListAllCollLimitQueries.vbs @@ -0,0 +1,20 @@ +strSMSServer = + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set colQueries = objSMS.ExecQuery _ + ("select * from SMS_Query where TargetClassName <> " & _ + "'SMS_StatusMessage' and LimitToCollectionID <> '' order by Name") +for each objQuery in colQueries + wscript.echo objQuery.Name & "(" & _ + objQuery.QueryID & ")" & objQuery.LimitToCollectionID +next diff --git a/Chapter09/9-11_CreatePromptedQuery.vbs b/Chapter09/9-11_CreatePromptedQuery.vbs new file mode 100644 index 0000000..a128951 --- /dev/null +++ b/Chapter09/9-11_CreatePromptedQuery.vbs @@ -0,0 +1,19 @@ +strSMSServer = + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +strQueryID = "LAB0001E" +strCollLimitID = "" + +Set objQuery = objSMS.Get("SMS_Query.QueryID='" & strQueryID & "'") +objQuery.LimitToCollectionID = strCollLimitID +objQuery.Put_ diff --git a/Chapter09/9-12_ModifyQueryPerms.vbs b/Chapter09/9-12_ModifyQueryPerms.vbs new file mode 100644 index 0000000..9e8c971 --- /dev/null +++ b/Chapter09/9-12_ModifyQueryPerms.vbs @@ -0,0 +1,30 @@ +'This script will grant the group "SMSVPC\Help Desk" read + ' permissions to Query ID "LAB00040". +strSMSServer = +strHelpDesk="SMSVPC\Help Desk" 'Domain\Group or username +strQueryID = "LAB00040" 'ID of the Query + + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set colQueries = objSMS.ExecQuery _ + ("Select * From SMS_Query where QueryID = '" & _ + strQueryID & "'") +For Each objQuery In colQueries + Set objNewRight = objSMS.Get _ + ("SMS_UserInstancePermissions").SpawnInstance_() + objNewRight.UserName = strHelpDesk + objNewRight.ObjectKey = 1 '1=collection + objNewRight.InstanceKey = objQuery.QueryID + objNewRight.InstancePermissions = 1 'grant Read + objNewRight.Put_ +Next diff --git a/Chapter09/9-13_DisplayQueryInstanceInfo_MOF.vbs b/Chapter09/9-13_DisplayQueryInstanceInfo_MOF.vbs new file mode 100644 index 0000000..ce135a6 --- /dev/null +++ b/Chapter09/9-13_DisplayQueryInstanceInfo_MOF.vbs @@ -0,0 +1,21 @@ +strSMSServer = +strQueryID = "LAB0001E" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set objQuery = objSMS.Get("SMS_Query.QueryID='" & strQueryID & "'") + +Set colQueryResults = objSMS.ExecQuery(objQuery.Expression) +For Each objResult In colQueryResults + 'use the following line to display all instance information + wscript.echo objResult.GetObjectText_ +Next diff --git a/Chapter09/9-14_DisplayQueryInstance_XML.vbs b/Chapter09/9-14_DisplayQueryInstance_XML.vbs new file mode 100644 index 0000000..190c400 --- /dev/null +++ b/Chapter09/9-14_DisplayQueryInstance_XML.vbs @@ -0,0 +1,21 @@ +Const wbemObjectTextFormatWMIDTD20 = 2 +strSMSServer = +strQueryID = "SMS012" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set objQuery = objSMS.Get("SMS_Query.QueryID='" & strQueryID & "'") + +Set colQueryResults = objSMS.ExecQuery(objQuery.Expression) +For Each objResult In colQueryResults + wscript.echo objResult.GetText_(wbemObjectTextFormatWMIDTD20) +Next diff --git a/Chapter09/9-15_ExportCustomQueries.vbs b/Chapter09/9-15_ExportCustomQueries.vbs new file mode 100644 index 0000000..d30dd3b --- /dev/null +++ b/Chapter09/9-15_ExportCustomQueries.vbs @@ -0,0 +1,50 @@ +Const ForWriting = 2 +Set fso = CreateObject("Scripting.FileSystemObject") + +strSMSServer = + +strNEWSMSServer = "MOFSMSSERVER" +strNewSMSSiteCode = "MOFSMSSITECODE" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set colQueries = objSMS.ExecQuery _ +("select * from SMS_Query where TargetClassName <> '" & _ +"SMS_StatusMessage' and QueryID not like 'SMS%'") + +for each objQuery in colQueries + wscript.echo "Exporting " & objQuery.Name & vbTAB & _ + objQuery.QueryID + Set fout = fso.OpenTextFile("C:\Scripts\sms\Queries\mofs\" & _ + objQuery.QueryID & ".MOF", ForWriting, True) + fout.writeline "//********************************" + fout.writeline "//Created by SMS Recipes Exporter" + fout.writeline "//********************************" + fout.writeline vbCRLF + 'only use the following line if planning to import MOF + 'from the command line + fout.writeline "#pragma namespace(" & chr(34) & "\\\\" & _ + strNEWSMSServer & "\\root\\SMS\\site_" & _ + strnewSMSSiteCode & chr(34) & ")" + fout.writeline vbCRLF + fout.writeline "// **** Class : SMS_Query ****" + for each strLine in split(objQuery.GetObjectText_, chr(10)) + if instr(strLine, "QueryID =") then + fout.writeline(vbTAB & "QueryID = " & chr(34) & _ + chr(34)) & ";" + else + fout.writeline cstr(strLine) + end if + next + fout.writeline "// **** End ****" + fout.close +next diff --git a/Chapter09/9-16_SampleQuery_MOF.mof b/Chapter09/9-16_SampleQuery_MOF.mof new file mode 100644 index 0000000..fb9c5ea --- /dev/null +++ b/Chapter09/9-16_SampleQuery_MOF.mof @@ -0,0 +1,21 @@ +//******************************** +//Created by SMS Recipes Exporter +//******************************** + + +#pragma namespace("\\\\MOFSMSSERVER\\root\\SMS\\site_MOFSMSSITECODE") + + +// **** Class : SMS_Query **** + +instance of SMS_Query +{ + Comments = ""; + Expression = "select MACAddresses, Name from SMS_R_System order by MACAddresses"; + LimitToCollectionID = ""; + Name = "All Systems with MAC addresses"; + QueryID = ""; + TargetClassName = "SMS_R_System"; +}; + +// **** End **** diff --git a/Chapter09/9-17_SampleSubSelect_SystemsWithoutAdobeAcrobat.txt b/Chapter09/9-17_SampleSubSelect_SystemsWithoutAdobeAcrobat.txt new file mode 100644 index 0000000..ee8817e --- /dev/null +++ b/Chapter09/9-17_SampleSubSelect_SystemsWithoutAdobeAcrobat.txt @@ -0,0 +1,13 @@ +select SMS_G_System_SYSTEM.Name + +from SMS_R_System inner join + SMS_G_System_SYSTEM on SMS_G_System_SYSTEM.ResourceID = + SMS_R_System.ResourceId + +where SMS_G_System_SYSTEM.Name not in + (select SMS_G_System_SYSTEM.Name from + SMS_R_System inner join SMS_G_System_SYSTEM on + SMS_G_System_SYSTEM.ResourceID = SMS_R_System.ResourceId + inner join SMS_G_System_SoftwareFile on + SMS_G_System_SoftwareFile.ResourceID = SMS_R_System.ResourceId + where SMS_G_System_SoftwareFile.FileName = "Acrobat.exe") diff --git a/Chapter09/9-19_SampleWQLWithGetDate.txt b/Chapter09/9-19_SampleWQLWithGetDate.txt new file mode 100644 index 0000000..2c1ff58 --- /dev/null +++ b/Chapter09/9-19_SampleWQLWithGetDate.txt @@ -0,0 +1,13 @@ +select + SMS_G_System_SYSTEM.Name, + SMS_G_System_WORKSTATION_STATUS.LastHardwareScan +from SMS_R_System inner join SMS_G_System_SYSTEM on + SMS_G_System_SYSTEM.ResourceID = SMS_R_System.ResourceId + inner join SMS_G_System_WORKSTATION_STATUS on + SMS_G_System_WORKSTATION_STATUS.ResourceID = + SMS_R_System.ResourceId +WHERE + (datediff(day, + SMS_G_System_WORKSTATION_STATUS.LastHardwareScan, + getdate()) >= 30) +Order by SMS_G_System_WORKSTATION_STATUS.LastHardwareScan DESC diff --git a/Chapter09/9-1_CreateAQuery.vbs b/Chapter09/9-1_CreateAQuery.vbs new file mode 100644 index 0000000..fb754e0 --- /dev/null +++ b/Chapter09/9-1_CreateAQuery.vbs @@ -0,0 +1,19 @@ +strSMSServer = +strQueryName = "Basic Query" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set newQuery = objSMS.Get("SMS_Query").SpawnInstance_() +newQuery.Name = strQueryName +newQuery.Expression = "select * from SMS_R_System" +newQuery.TargetClassName = "SMS_R_System" +newQuery.Put_ diff --git a/Chapter09/9-20_CreateQueryFolder.vbs b/Chapter09/9-20_CreateQueryFolder.vbs new file mode 100644 index 0000000..ba29fed --- /dev/null +++ b/Chapter09/9-20_CreateQueryFolder.vbs @@ -0,0 +1,21 @@ +strSMSServer = + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +strNewFolderName = "Admin Queries" + +Set newFolder = objSMS.Get("SMS_ObjectContainerNode") _ + .SpawnInstance_() +newFolder.Name = strNewFolderName +newFolder.ObjectType = 7 'Query +newFolder.ParentContainerNodeId = 0 +newFolder.Put_ diff --git a/Chapter09/9-21_MovingQueriesBetweenFolders.vbs b/Chapter09/9-21_MovingQueriesBetweenFolders.vbs new file mode 100644 index 0000000..c930f10 --- /dev/null +++ b/Chapter09/9-21_MovingQueriesBetweenFolders.vbs @@ -0,0 +1,25 @@ +strSMSServer = +strQueryIDs = "LAB0001E,LAB0001F,LAB0002E" +'to move more than one, separate with commas + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + + +intSourceFolder=0 'Source Folder (root node in this case) +intDestFolder=10 'Destination Folder +intObjectType=7 '7=Query for type of object + +Set objFolder = objSMS.Get("SMS_ObjectContainerItem") +arrQueryIDs = split(strQueryIDs, ",") +retval = objFolder.MoveMembers _ +(arrQueryIDs, intSourceFolder, intDestFolder , intObjectType) +wscript.echo retval diff --git a/Chapter09/9-2_CreateQuery-VerifyName.vbs b/Chapter09/9-2_CreateQuery-VerifyName.vbs new file mode 100644 index 0000000..ecc5a48 --- /dev/null +++ b/Chapter09/9-2_CreateQuery-VerifyName.vbs @@ -0,0 +1,36 @@ +strSMSServer = +strQueryName = "Basic Query" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +if QueryDoesntExist(strQueryname) then + Set newQuery = objSMS.Get("SMS_Query").SpawnInstance_() + newQuery.Name = strQueryName + newQuery.Expression = "select * from SMS_R_System" + newQuery.TargetClassName = "SMS_R_System" + newQuery.Put_ +else + wscript.echo "Query named " & chr(34) & strQueryname & _ + chr(34) & " already exists!" +end if + +'function used to verify query name doesn't exist +Function QueryDoesntExist(strName) + Set colQueries = objSMS.ExecQuery _ + ("select * from SMS_Query where TargetClassName <> '" & _ + "SMS_StatusMessage" & "' and Name = '" & strName & "'") + if colQueries.Count > 0 then + QueryDoesntExist = False + else + QueryDoesntExist = True + end if +End Function diff --git a/Chapter09/9-3_ListQueries.vbs b/Chapter09/9-3_ListQueries.vbs new file mode 100644 index 0000000..0ad2eb7 --- /dev/null +++ b/Chapter09/9-3_ListQueries.vbs @@ -0,0 +1,20 @@ +strSMSServer = + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set colQueries = objSMS.ExecQuery _ + ("select * from SMS_Query where TargetClassName <> " & _ + "'SMS_StatusMessage' order by Name") +for each objQuery in colQueries + wscript.echo objQuery.Name & "(" & _ + objQuery.QueryID & ")" & vbTAB & objQuery.Expression +next diff --git a/Chapter09/9-4_DeleteQuery.vbs b/Chapter09/9-4_DeleteQuery.vbs new file mode 100644 index 0000000..9699828 --- /dev/null +++ b/Chapter09/9-4_DeleteQuery.vbs @@ -0,0 +1,21 @@ +strSMSServer = +strQueryName = "Basic Query" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set colQueries = objSMS.ExecQuery _ + ("select * from SMS_Query where Name = '" & strQueryName & "'") +for each objQuery in colQueries + wscript.echo "Deleting " & objQuery.Name & "(" & _ + objQuery.QueryID & ")" + objQuery.Delete_ +next diff --git a/Chapter09/9-5_DeleteMultipleQueries.vbs b/Chapter09/9-5_DeleteMultipleQueries.vbs new file mode 100644 index 0000000..4c108a5 --- /dev/null +++ b/Chapter09/9-5_DeleteMultipleQueries.vbs @@ -0,0 +1,21 @@ +strSMSServer = + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +'to delete more than one, separate with commas as shown below +strQueryIDs = "LAB00001,LAB00002,LAB00014" +arrQueryIDs = split(strQueryIDs, ",") + +for each strQueryID in arrQueryIDs + Set objQuery = objSMS.Get ("SMS_Query.QueryID='" & strQueryID & "'") + objQuery.Delete_ +next diff --git a/Chapter09/9-6_ModifyQuery.vbs b/Chapter09/9-6_ModifyQuery.vbs new file mode 100644 index 0000000..cc6c702 --- /dev/null +++ b/Chapter09/9-6_ModifyQuery.vbs @@ -0,0 +1,20 @@ +strSMSServer = + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +strQueryID = "LAB0001D" + +Set objQuery = objSMS.Get("SMS_Query.QueryID='" & _ + strQueryID & "'") +objQuery.Comments = "Use this query to display all systems " & _ + "in the SMS_R_System class" +objQuery.Put_ diff --git a/Chapter09/9-8_DisplayWQL.vbs b/Chapter09/9-8_DisplayWQL.vbs new file mode 100644 index 0000000..84b1d07 --- /dev/null +++ b/Chapter09/9-8_DisplayWQL.vbs @@ -0,0 +1,16 @@ +strSMSServer = +strQueryID = "LAB0001D" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set objQuery = objSMS.Get("SMS_Query.QueryID='" & strQueryID & "'") +wscript.echo objQuery.Expression diff --git a/Chapter09/9-9_CollectionLimitQuery.vbs b/Chapter09/9-9_CollectionLimitQuery.vbs new file mode 100644 index 0000000..f42ae3e --- /dev/null +++ b/Chapter09/9-9_CollectionLimitQuery.vbs @@ -0,0 +1,19 @@ +strSMSServer = +strQueryID = "LAB0001E" +strCollLimitID = "LAB00017" 'the collection to limit to + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set objQuery = objSMS.Get("SMS_Query.QueryID='" & _ + strQueryID & "'") +objQuery.LimitToCollectionID = strCollLimitID +objQuery.Put_ diff --git a/Chapter10/10-1_SWInvQuery.vbs b/Chapter10/10-1_SWInvQuery.vbs new file mode 100644 index 0000000..19b5118 --- /dev/null +++ b/Chapter10/10-1_SWInvQuery.vbs @@ -0,0 +1,32 @@ +strSMSServer = + +strFileName = "Acrobat.exe" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +strSQL = "select SMS_R_System.Name, " & _ + "SMS_G_System_SoftwareFile.FileName, " & _ + "SMS_G_System_SoftwareFile.FileDescription, " & _ + "SMS_G_System_SoftwareFile.FileVersion from " & _ + "SMS_R_System inner join SMS_G_System_SoftwareFile on " & _ + "SMS_G_System_SoftwareFile.ResourceID = " & _ + "SMS_R_System.ResourceId where " & _ + "SMS_G_System_SoftwareFile.FileName = '" & strFileName & "'" + +Set colSystems = objSMS.ExecQuery(strSQL) + +for each objSystem in colSystems + wscript.echo objSystem.SMS_R_System.Name & vbTAB & _ + objSystem.SMS_G_System_SoftwareFile.FileName & vbTAB & _ + objSystem.SMS_G_System_SoftwareFile.FileDescription & vbTAB & _ + objSystem.SMS_G_System_SoftwareFile.FileVersion +next diff --git a/Chapter10/10-2_ListCollectedFilesForSpecificSystem.vbs b/Chapter10/10-2_ListCollectedFilesForSpecificSystem.vbs new file mode 100644 index 0000000..9e7d497 --- /dev/null +++ b/Chapter10/10-2_ListCollectedFilesForSpecificSystem.vbs @@ -0,0 +1,42 @@ +strSMSServer = + +strComputer = "2kPro" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +strSQL = "SELECT sys.Name, colFil.FileName, " & _ + "colFil.FileSize, colFil.ModifiedDate, colFil.FilePath, " & _ + "colFil.LocalFilePath, colFil.CollectionDate " & _ + "FROM SMS_G_System_CollectedFile colFil INNER JOIN " & _ + "SMS_R_System sys ON " & _ + "colFil.ResourceID = sys.ResourceID " & _ + "WHERE sys.Name = '" & strComputer & "'" + +Set colFiles = objSMS.ExecQuery(strSQL) +for each objFile in colFiles + wscript.echo objFile.sys.Name & vbTAB & _ + objFile.colFil.FileName & vbTAB & _ + objFile.colFil.FileSize & vbTAB & _ + WMIDateStringToDate(objFile.colFil.ModifiedDate) & _ + vbTAB & objFile.colFil.FilePath & vbTAB & _ + objFile.colFil.LocalFilePath & vbTAB & _ + WMIDateStringToDate(objFile.colFil.CollectionDate) +next + +Function WMIDateStringToDate(dtmInstallDate) + WMIDateStringToDate = CDate(Mid(dtmInstallDate, 5, 2) & _ + "/" & Mid(dtmInstallDate, 7, 2) & "/" & _ + Left(dtmInstallDate, 4) & " " & _ + Mid (dtmInstallDate, 9, 2) & ":" & _ + Mid(dtmInstallDate, 11, 2) & ":" & Mid(dtmInstallDate, _ + 13, 2)) +End Function diff --git a/Chapter10/10-3_ListSpecificFileForAllSystems.vbs b/Chapter10/10-3_ListSpecificFileForAllSystems.vbs new file mode 100644 index 0000000..f09e58d --- /dev/null +++ b/Chapter10/10-3_ListSpecificFileForAllSystems.vbs @@ -0,0 +1,29 @@ +strSMSServer = + +strFileName = "dbcfg.ini" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +strSQL = "SELECT sys.Name, colFil.FileName, " & _ + "colFil.LocalFilePath, colFil.RevisionID " & _ + "FROM SMS_G_System_CollectedFile colFil INNER JOIN " & _ + "SMS_R_System sys ON " & _ + "colFil.ResourceID = sys.ResourceID " & _ + "WHERE colFil.FileName = '" & strFileName & "'" + +Set colFiles = objSMS.ExecQuery(strSQL) + +for each objFile in colFiles + wscript.echo objFile.sys.Name & vbTAB & _ + objfile.colFil.FileName & vbTAB & _ + objFile.colFil.LocalFilePath +next diff --git a/Chapter10/10-4_ExtractCollectedFilesForAllSystems.vbs b/Chapter10/10-4_ExtractCollectedFilesForAllSystems.vbs new file mode 100644 index 0000000..410efa4 --- /dev/null +++ b/Chapter10/10-4_ExtractCollectedFilesForAllSystems.vbs @@ -0,0 +1,37 @@ +Const OverwriteExisting = TRUE + +strSMSServer = + +strFileName = "dbcfg.ini" +strTargetPath = "\\smsvpc\fileanalysis" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +strSQL = "SELECT sys.Name, colFil.FileName, " & _ + "colFil.LocalFilePath, colFil.RevisionID " & _ + "FROM SMS_G_System_CollectedFile colFil INNER JOIN " & _ + "SMS_R_System sys ON " & _ + "colFil.ResourceID = sys.ResourceID " & _ + "WHERE colFil.FileName = '" & strFileName & "'" + +Set colFiles = objSMS.ExecQuery(strSQL) + +for each objFile in colFiles + wscript.echo objFile.sys.Name & vbTAB & _ + objfile.colFil.FileName & vbTAB & _ + objFile.colFil.LocalFilePath + Set objFSO = CreateObject("Scripting.FileSystemObject") + objFSO.CopyFile objFile.colFil.LocalFilePath , _ + strTargetPath & "\" & objFile.sys.Name & "__" & _ + objfile.colFil.RevisionID & "__" & _ + objfile.colFil.FileName, OverwriteExisting +next diff --git a/Chapter10/10-5_SearchINIForSpecificData.vbs b/Chapter10/10-5_SearchINIForSpecificData.vbs new file mode 100644 index 0000000..56dbb8e --- /dev/null +++ b/Chapter10/10-5_SearchINIForSpecificData.vbs @@ -0,0 +1,45 @@ +Const ForReading = 1 +strSMSServer = + +strFileName = "dbcfg.ini" +strDataToCheck = "DBServername=MYPRODSERVER" +intCount = 0 +Set objFSO = CreateObject("Scripting.FileSystemObject") + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +strSQL = "SELECT sys.Name, colFil.FileName, " & _ + "colFil.LocalFilePath, colFil.RevisionID " & _ + "FROM SMS_G_System_CollectedFile colFil INNER JOIN " & _ + "SMS_R_System sys ON " & _ + "colFil.ResourceID = sys.ResourceID " & _ + "WHERE colFil.FileName = '" & strFileName & "' " & _ + "ORDER BY colFil.CollectionDate" + +Set colFiles = objSMS.ExecQuery(strSQL) + +for each objFile in colFiles + intCount = intCount + 1 + wscript.echo "Checking " & objFile.sys.Name & ". . ." + Set objReadFile = objFSO.OpenTextFile _ + (objFile.colFil.LocalFilePath, ForReading) + strContents = objReadFile.ReadAll + if instr(ucase(strContents), ucase(strDataToCheck)) = 0 then + strInfo = strInfo & objFile.sys.Name & vbTAB & _ + objFile.colFil.RevisionID & vbCRLF + end if +next + +wscript.echo vbCRLF & intCount & " Files Checked" & vbCRLF +wscript.echo "The following computers do not have " & _ + strServerName & "in the file " & strFileName +wscript.echo strInfo diff --git a/Chapter11/11-9_HWInvQuery.vbs b/Chapter11/11-9_HWInvQuery.vbs new file mode 100644 index 0000000..a451041 --- /dev/null +++ b/Chapter11/11-9_HWInvQuery.vbs @@ -0,0 +1,28 @@ +strSMSServer = "SMSVPC" +strComputer = "2KPRO" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +strWQL = "select arp.*, sys.Name from SMS_R_System sys " & _ + "inner join SMS_G_System_ADD_REMOVE_PROGRAMS arp on " & _ + "arp.ResourceID = sys.ResourceId where sys.Name = '" & _ + strComputer & "' order by arp.DisplayName" + +Set colARPs = objSMS.ExecQuery(strWQL) + +wscript.echo "Add/Remove Programs information for " & strComputer +for each objARP in colARPs + wscript.echo objARP.arp.DisplayName & vbTAB & _ + objARP.arp.InstallDate & vbTAB & objARP.arp.Publisher +next + + diff --git a/Chapter12/12-1_TurnOffPermissionRequired.mof b/Chapter12/12-1_TurnOffPermissionRequired.mof new file mode 100644 index 0000000..67a862d --- /dev/null +++ b/Chapter12/12-1_TurnOffPermissionRequired.mof @@ -0,0 +1,16 @@ +#pragma namespace("\\\\.\\root\\ccm\\policy\\machine\\requestedconfig") + +[CCM_Policy_PartialPolicy(true)] +instance of CCM_RemoteToolsConfig + +{ + + + +PolicySource = "local"; +Type = 1; + +[ccm_policy_override(TRUE)] +PermissionRequired = false; + +}; diff --git a/Chapter12/12-2_RemoveLocalRemoteToolsPolicies.vbs b/Chapter12/12-2_RemoveLocalRemoteToolsPolicies.vbs new file mode 100644 index 0000000..192a086 --- /dev/null +++ b/Chapter12/12-2_RemoveLocalRemoteToolsPolicies.vbs @@ -0,0 +1,12 @@ +strComputer = "." +Set objWMIService = GetObject _ + ("winmgmts:{impersonationLevel=impersonate}!\\" & _ + strComputer & "\root\ccm\Policy\Machine\RequestedConfig") +Set colLocalPolicy = objWMIService.ExecQuery _ + ("Select * from CCM_RemoteToolsConfig " & _ + "where policysource = 'local'") + +for each objPolicy in colLocalPolicy + objPolicy.Delete_ +next + diff --git a/Chapter13/13-1_ModifyShortcuts.vbs b/Chapter13/13-1_ModifyShortcuts.vbs new file mode 100644 index 0000000..09134b3 --- /dev/null +++ b/Chapter13/13-1_ModifyShortcuts.vbs @@ -0,0 +1,31 @@ +strNewAccess = ucase("c:\program Files\microsoft " & _ + "office\office11\msaccess.EXE") + +strComputer = "." 'connecting to local computer + +Set objWMIService = GetObject _ + ("winmgmts:\\" & strComputer & "\root\cimv2") +Set colFiles = objWMIService. _ + ExecQuery("Select * from CIM_DataFile where Extension = 'lnk'") + For Each objFile in colFiles + CheckShortcut(objFile.Name) + Next + +Sub CheckShortcut(strName) + wscript.echo strName + 'this actually looks inside the shortcut and modifies + ' "targetpath" as needed. This only affects the target, + ' not the arguments after the target. + Set WshShell = wscript.CreateObject("WScript.Shell") + 'using create is a bit confusing. If it already exists, + ' CreateShortcut edits instead of creates. + Set oShellLink = WshShell.CreateShortcut(strName) + + If InStr(1, UCase(oShellLink.TargetPath), _ + UCase("MSACCESS.EXE")) Then + oShellLink.TargetPath = strNewAccess + oShellLink.IconLocation = strNewAccess + End If + oShellLink.Save +end sub + \ No newline at end of file diff --git a/Chapter13/13-2_FindFileAndReplace.vbs b/Chapter13/13-2_FindFileAndReplace.vbs new file mode 100644 index 0000000..8eb3206 --- /dev/null +++ b/Chapter13/13-2_FindFileAndReplace.vbs @@ -0,0 +1,29 @@ +Const OverwriteExisting = TRUE +strComputer = "." +'Because of CIM_DataFile, split File Name and Extension into +' two variables +strFileName = "Foo" +strFileExt = "doc" +strNewFileName = "Foo2.doc" + +'use this to obtain the current path to the VBScript +Set objFso= createobject("Scripting.FileSystemObject") +strScriptPath = objFso.GetParentFolderName(WScript.ScriptFullName) + +Set objWMIService = GetObject("winmgmts:" _ + & "{impersonationLevel=impersonate}!\\" & _ + strComputer & "\root\cimv2") + +'WQL query - notice we're only looking for files on C: +Set colFiles = objWMIService.ExecQuery _ + ("Select * from CIM_Datafile where FileName = '" & _ + strFileName & "' and Extension = '" & strFileExt & _ + "' and drive = 'C:'") + +For Each objFile in colFiles + 'rename file + objFile.Rename(objFile.Name & ".bak") + 'copy the new file + objFSO.CopyFile strScriptPath & "\" & strNewFileName,_ + objFile.Drive & objFile.Path, OverwriteExisting +Next diff --git a/Chapter13/CreateShortcutOnAllUsersDesktop.ipf b/Chapter13/CreateShortcutOnAllUsersDesktop.ipf new file mode 100644 index 0000000..36cdd2b --- /dev/null +++ b/Chapter13/CreateShortcutOnAllUsersDesktop.ipf @@ -0,0 +1,67 @@ +Document Type: IPF +item: Global + Version=6.0 + Title English=Icon To All Users Desktop + Flags=01000100 + Languages=0 0 65 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + LanguagesList=English + Default Language=2 + Copy Default=1 + Japanese Font Name=MS Gothic + Japanese Font Size=9 + Start Gradient=0 0 255 + End Gradient=0 0 0 + Windows Flags=00010100000000000010110000011010 + Message Font=MS Sans Serif + Font Size=8 + Disk Filename=SETUP + Patch Flags=0000000000000001 + Patch Threshold=85 + Patch Memory=4000 + FTP Cluster Size=20 + Variable Name1=_SYS_ + Variable Default1=C:\WINDOWS\system32 + Variable Flags1=00001000 + Variable Name2=_SMSINSTL_ + Variable Default2=C:\Program Files\Microsoft SMS Installer + Variable Flags2=00001000 +end +item: Remark + Text=Define variables for ease-of-use +end +item: Set Variable + Variable=IEXPLORE + Value=c:\Program Files\Internet Explorer\iexplore.exe +end +item: Set Variable + Variable=URL + Value=www.microsoft.com/technet +end +item: Set Variable + Variable=URLCOMMENTS + Value=Launch Microsoft Technet +end +item: Remark +end +item: Remark + Text=Obtain the path to the All Users Desktop +end +item: Get Registry Key Value + Variable=ALLUSERSDSKTP + Key=Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders + Value Name=Common Desktop + Flags=00000100 +end +item: Remark +end +item: Remark + Text=Create the Icon (OverWrite if it already exists) +end +item: Create Shortcut + Source English=%IEXPLORE% + Destination English=%ALLUSERSDSKTP%\Launch TechNet.lnk + Command Options English=%URL% + Description English=%URLCOMMENTS% + Key Type English=1536 + Flags=00000001 +end diff --git a/Chapter13/CreateShortcutOnEachUsersDesktop.ipf b/Chapter13/CreateShortcutOnEachUsersDesktop.ipf new file mode 100644 index 0000000..7879a82 --- /dev/null +++ b/Chapter13/CreateShortcutOnEachUsersDesktop.ipf @@ -0,0 +1,122 @@ +Document Type: IPF +item: Global + Version=6.0 + Title English=Create Shortcut on Each Users Desktop + Flags=01000100 + Languages=0 0 65 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + LanguagesList=English + Default Language=2 + Copy Default=1 + Japanese Font Name=MS Gothic + Japanese Font Size=9 + Start Gradient=0 0 255 + End Gradient=0 0 0 + Windows Flags=00010100000000000010110001011010 + Message Font=MS Sans Serif + Font Size=8 + Disk Filename=SETUP + Patch Flags=0000000000000001 + Patch Threshold=85 + Patch Memory=4000 + FTP Cluster Size=20 + Variable Name1=_SYS_ + Variable Default1=C:\WINDOWS\system32 + Variable Flags1=00001000 + Variable Name2=_SMSINSTL_ + Variable Default2=C:\Program Files\Microsoft SMS Installer + Variable Flags2=00001000 +end +item: Remark + Text=Obtain the path to the All Users Desktop +end +item: Get Registry Key Value + Variable=ALLUSERSDSKTP + Key=Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders + Value Name=Common Desktop + Flags=00000100 +end +item: Remark +end +item: Remark + Text=Parse string ALLUSERSDSKTP to extract Profile Paths +end +item: Parse String + Source=%ALLUSERSDSKTP% + Pattern=\All Users + Variable1=PROFILEPATH + Variable2=TMPJUNK + Flags=00000010 +end +item: Remark +end +item: Remark + Text=Get the TEMP environement variable +end +item: Get Environment Variable + Variable=SYSTEMP + Environment=TEMP +end +item: Remark +end +item: Remark + Text=Install the icon file locally +end +item: Install File + Source=\\MySMSServer\SourceFiles\GoogleLaunch\GoogleLocal.ico + Destination=%SYSWIN%\GoogleLocal.ico + Flags=0000000000000010 +end +item: Remark +end +item: Remark + Text=Execute Command to create %temp%\users.txt, and wait... +end +item: Execute Program + Pathname=cmd.exe + Command Line=/c dir /b /ad "%PROFILEPATH%">%SYSTEMP%\users.txt + Flags=00000010 +end +item: Remark +end +item: Remark + Text=Read each line of users.txt, and use the username to comlete the path +end +item: Remark + Text= to the user's desktop +end +item: Read/Update Text File + Variable=USERNAME + Pathname=%SYSTEMP%\users.txt +end +item: If/While Statement + Variable=USERNAME + Value=Administrator + Flags=00000101 +end +item: If/While Statement + Variable=USERNAME + Value=All Users + Flags=00000101 +end +item: Create Shortcut + Source English=c:\Program Files\Internet Explorer\iexplore.exe + Destination English=%PROFILEPATH%\%USERNAME%\Desktop\GoogleLocal.lnk + Command Options English=http://www.google.com/local + Icon Pathname English=%SYSWIN%\googlelocal.ico + Description English=Launch Google Local! + Key Type English=1536 + Flags=00000001 +end +item: End Block +end +item: End Block +end +item: End Block +end +item: Remark +end +item: Delete File + Pathname=%SYSTEMP%\users.txt +end +item: Remark +end diff --git a/Chapter13/CreateShortcutOnEachUsersQuickLaunch.ipf b/Chapter13/CreateShortcutOnEachUsersQuickLaunch.ipf new file mode 100644 index 0000000..5c057e1 --- /dev/null +++ b/Chapter13/CreateShortcutOnEachUsersQuickLaunch.ipf @@ -0,0 +1,126 @@ +Document Type: IPF +item: Global + Version=6.0 + Title English=Create Shortcut on Each Users Quick Launch + Flags=01000100 + Languages=0 0 65 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + LanguagesList=English + Default Language=2 + Copy Default=1 + Japanese Font Name=MS Gothic + Japanese Font Size=9 + Start Gradient=0 0 255 + End Gradient=0 0 0 + Windows Flags=00010100000000000010110001011010 + Message Font=MS Sans Serif + Font Size=8 + Disk Filename=SETUP + Patch Flags=0000000000000001 + Patch Threshold=85 + Patch Memory=4000 + FTP Cluster Size=20 + Variable Name1=_SYS_ + Variable Default1=C:\WINDOWS\system32 + Variable Flags1=00001000 + Variable Name2=_SMSINSTL_ + Variable Default2=C:\Program Files\Microsoft SMS Installer + Variable Flags2=00001000 +end +item: Set Variable + Variable=QLAUNCH + Value=Application Data\Microsoft\Internet Explorer\Quick Launch +end +item: Remark + Text=Obtain the path to the All Users Desktop +end +item: Get Registry Key Value + Variable=ALLUSERSDSKTP + Key=Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders + Value Name=Common Desktop + Flags=00000100 +end +item: Remark +end +item: Remark + Text=Parse string ALLUSERSDSKTP to extract Profile Paths +end +item: Parse String + Source=%ALLUSERSDSKTP% + Pattern=\All Users + Variable1=PROFILEPATH + Variable2=TMPJUNK + Flags=00000010 +end +item: Remark +end +item: Remark + Text=Get the TEMP environement variable +end +item: Get Environment Variable + Variable=SYSTEMP + Environment=TEMP +end +item: Remark +end +item: Remark + Text=Install the icon file locally +end +item: Install File + Source=\\MySMSServer\SourceFiles\GoogleLaunch\GoogleLocal.ico + Destination=%SYSWIN%\GoogleLocal.ico + Flags=0000000000000010 +end +item: Remark +end +item: Remark + Text=Execute Command to create %temp%\users.txt, and wait... +end +item: Execute Program + Pathname=cmd.exe + Command Line=/c dir /b /ad "%PROFILEPATH%">%SYSTEMP%\users.txt + Flags=00000010 +end +item: Remark +end +item: Remark + Text=Read each line of users.txt, and use the username to comlete the path +end +item: Remark + Text= to the user's quick Launch +end +item: Read/Update Text File + Variable=USERNAME + Pathname=%SYSTEMP%\users.txt +end +item: If/While Statement + Variable=USERNAME + Value=Administrator + Flags=00000101 +end +item: If/While Statement + Variable=USERNAME + Value=All Users + Flags=00000101 +end +item: Create Shortcut + Source English=c:\Program Files\Internet Explorer\iexplore.exe + Destination English=%PROFILEPATH%\%USERNAME%\%QLaunch%\GoogleLocal.lnk + Command Options English=http://www.google.com/local + Icon Pathname English=%SYSWIN%\googlelocal.ico + Description English=Launch Google Local! + Key Type English=1536 + Flags=00000001 +end +item: End Block +end +item: End Block +end +item: End Block +end +item: Remark +end +item: Delete File + Pathname=%SYSTEMP%\users.txt +end +item: Remark +end diff --git a/Chapter13/FindFileAndReplace.ipf b/Chapter13/FindFileAndReplace.ipf new file mode 100644 index 0000000..1b5913a --- /dev/null +++ b/Chapter13/FindFileAndReplace.ipf @@ -0,0 +1,74 @@ +Document Type: IPF +item: Global + Version=6.0 + Flags=01000100 + Languages=0 0 65 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + LanguagesList=English + Default Language=2 + Copy Default=1 + Japanese Font Name=MS Gothic + Japanese Font Size=9 + Start Gradient=0 0 255 + End Gradient=0 0 0 + Windows Flags=00010100000000000010110001011010 + Message Font=MS Sans Serif + Font Size=8 + Disk Filename=SETUP + Patch Flags=0000000000000001 + Patch Threshold=85 + Patch Memory=4000 + FTP Cluster Size=20 +end +item: Remark +end +item: Remark + Text=File to find +end +item: Set Variable + Variable=FINDFILE + Value=Foo.doc +end +item: Set Variable + Variable=FOUNDFILE +end +item: Remark +end +item: Remark + Text=While Loop (perform loop at least once) +end +item: If/While Statement + Variable=FOUNDFILE + Flags=00110001 +end +item: Remark +end +item: Search for File + Variable=FOUNDFILE + Pathname List=%FINDFILE% + Flags=00000001 +end +item: Remark +end +item: If/While Statement + Variable=FOUNDFILE + Flags=00000001 +end +item: Rename File/Directory + Old Pathname=%FOUNDFILE%\%FINDFILE% + New Filename=%FINDFILE%.Bak +end +item: Install File + Source=\\smsserver\soruces\FooDoc\Foo2.doc + Destination=%FOUNDFILE%\Foo2.doc + Flags=0000000000000010 +end +item: End Block +end +item: Remark +end +item: End Block +end +item: Remark +end +item: Remark +end diff --git a/Chapter13/FindFileAndReplace_II.ipf b/Chapter13/FindFileAndReplace_II.ipf new file mode 100644 index 0000000..cfa913e --- /dev/null +++ b/Chapter13/FindFileAndReplace_II.ipf @@ -0,0 +1,111 @@ +Document Type: IPF +item: Global + Version=6.0 + Flags=01000100 + Languages=0 0 65 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + LanguagesList=English + Default Language=2 + Copy Default=1 + Japanese Font Name=MS Gothic + Japanese Font Size=9 + Start Gradient=0 0 255 + End Gradient=0 0 0 + Windows Flags=00010100000000000010110001011010 + Message Font=MS Sans Serif + Font Size=8 + Disk Filename=SETUP + Patch Flags=0000000000000001 + Patch Threshold=85 + Patch Memory=4000 + FTP Cluster Size=20 +end +item: Remark +end +item: Remark + Text=File to find +end +item: Set Variable + Variable=FINDFILE + Value=Foo.doc +end +item: Set Variable + Variable=FOUNDFILE +end +item: Remark +end +item: Remark + Text=While Loop (perform loop at least once) +end +item: If/While Statement + Variable=FOUNDFILE + Flags=00110001 +end +item: Remark +end +item: Search for File + Variable=FOUNDFILE + Pathname List=%FINDFILE% + Flags=00000001 +end +item: Remark +end +item: If/While Statement + Variable=FOUNDFILE + Flags=00000001 +end +item: Rename File/Directory + Old Pathname=%FOUNDFILE%\%FINDFILE% + New Filename=%FINDFILE%.Bak +end +item: End Block +end +item: Remark +end +item: End Block +end +item: Remark +end +item: Set Variable + Variable=FOUNDFILE +end +item: Remark + Text=While Loop (perform loop at least once) +end +item: If/While Statement + Variable=FOUNDFILE + Flags=00110001 +end +item: Remark +end +item: Search for File + Variable=FOUNDFILE + Pathname List=%FINDFILE%.bak + Flags=00000001 +end +item: Remark +end +item: If/While Statement + Variable=FOUNDFILE + Flags=00000001 +end +item: Rename File/Directory + Old Pathname=%FOUNDFILE%\%FINDFILE%.Bak + New Filename=%FINDFILE%.Bak.Old +end +item: Install File + Source=C:\scripts\sms\swdist\Foo2.doc + Destination=%FOUNDFILE%\Foo.doc + Flags=0000000000000010 +end +item: End Block +end +item: Remark +end +item: End Block +end +item: Remark +end +item: Remark +end +item: Remark +end diff --git a/Chapter13/HKCU_RegMod.ipf b/Chapter13/HKCU_RegMod.ipf new file mode 100644 index 0000000..f748309 --- /dev/null +++ b/Chapter13/HKCU_RegMod.ipf @@ -0,0 +1,108 @@ +Document Type: IPF +item: Global + Version=6.0 + Flags=01000100 + Languages=0 0 65 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + LanguagesList=English + Default Language=2 + Copy Default=1 + Japanese Font Name=MS Gothic + Japanese Font Size=9 + Start Gradient=0 0 255 + End Gradient=0 0 0 + Windows Flags=00010100000000000010110001011010 + Message Font=MS Sans Serif + Font Size=8 + Disk Filename=SETUP + Patch Flags=0000000000000001 + Patch Threshold=85 + Patch Memory=4000 + FTP Cluster Size=20 +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark + Text=Install the File to be Run when the user logs in +end +item: Install File + Source=c:\temp\CLAIM_HKCUMOD.EXE + Destination=%SYSWIN%\CLAIM_HKCUMOD.exe + Flags=0000000000000010 +end +item: Remark +end +item: Remark + Text=Add/Update Registry keys in ActiveSetup +end +item: Edit Registry + Total Keys=1 + Key=SOFTWARE\Microsoft\Active Setup\Installed Components\CLAIM_HKCUMOD + New Value=%SYSWIN%\CLAIM_HKCUMOD.EXE /s + Value Name=StubPath + Root=2 +end +item: Edit Registry + Total Keys=1 + Key=SOFTWARE\Microsoft\Active Setup\Installed Components\CLAIM_HKCUMOD + New Value=1 + Value Name=Version + Root=2 +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark +end +item: Remark +end diff --git a/Chapter13/foo2.doc b/Chapter13/foo2.doc new file mode 100644 index 0000000..916c579 Binary files /dev/null and b/Chapter13/foo2.doc differ diff --git a/Chapter15/15-1_DisplayStatusMessageQuery.vbs b/Chapter15/15-1_DisplayStatusMessageQuery.vbs new file mode 100644 index 0000000..22914ad --- /dev/null +++ b/Chapter15/15-1_DisplayStatusMessageQuery.vbs @@ -0,0 +1,19 @@ +strQueryID = "SMS577" +strSMSServer = + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set objQuery = objSMS.Get("SMS_Query.QueryID='" & _ + strQueryID & "'") +wscript.echo objQuery.Expression +wscript.echo objQuery.GetObjectText_ +wscript.echo objQuery.GetText_(2) \ No newline at end of file diff --git a/Chapter15/15-2_DisplayStatusMessageQueries.vbs b/Chapter15/15-2_DisplayStatusMessageQueries.vbs new file mode 100644 index 0000000..8a80d70 --- /dev/null +++ b/Chapter15/15-2_DisplayStatusMessageQueries.vbs @@ -0,0 +1,20 @@ +strSMSServer = + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set colQueries = objSMS.ExecQuery _ + ("select * from SMS_Query where TargetClassName = " & _ + "'SMS_StatusMessage' order by Name") +for each objQuery in colQueries + wscript.echo objQuery.Name & "(" & _ + objQuery.QueryID & ")" & vbTAB & objQuery.Expression +next diff --git a/Chapter15/15-3_ExportStatusMessagesToMOF.vbs b/Chapter15/15-3_ExportStatusMessagesToMOF.vbs new file mode 100644 index 0000000..cef3922 --- /dev/null +++ b/Chapter15/15-3_ExportStatusMessagesToMOF.vbs @@ -0,0 +1,50 @@ +Const ForWriting = 2 +Set fso = CreateObject("Scripting.FileSystemObject") +strSMSServer = +strNEWSMSServer = "SMSVPC" +strNewSMSSiteCode = "LAB" +strFileLoc = "C:\scripts\" + +Set objLoc = CreateObject("WbemScripting.SWbemLocator") +Set objSMS= objLoc.ConnectServer(strSMSServer, "root\sms") +Set Results = objSMS.ExecQuery _ + ("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true") +For each Loc in Results + If Loc.ProviderForLocalSite = True Then + Set objSMS = objLoc.ConnectServer(Loc.Machine, "root\sms\site_" & _ + Loc.SiteCode) + end if +Next + +Set colStatQueries = objSMS.ExecQuery _ +("select * from SMS_Query where TargetClassName = '" & _ +"SMS_StatusMessage' and QueryID not like 'SMS%'") + +for each objStatQuery in colStatQueries + wscript.echo "Exporting " & objStatQuery.Name & vbTAB & _ + objStatQuery.QueryID + Set fin = fso.OpenTextFile(strfileLoc & _ + objStatQuery.QueryID & ".MOF", ForWriting, True) + fin.writeline "//********************************" + fin.writeline "//Created by SMS Recipes Exporter" + fin.writeline "//********************************" + fin.writeline vbCRLF + 'only use the following line if planning to import MOF + 'from the command line + fin.writeline "#pragma namespace(" & chr(34) & "\\\\" & _ + strNEWSMSServer & "\\root\\SMS\\site_" & _ + strnewSMSSiteCode & chr(34) & ")" + fin.writeline vbCRLF + fin.writeline "// **** Class : SMS_Query ****" + fin.writeline "[SecurityVerbs(140551)]" + for each strLine in split(objStatQuery.GetObjectText_, chr(10)) + if instr(strLine, "QueryID =") then + fin.writeline(vbTAB & "QueryID = " & chr(34) & _ + chr(34)) & ";" + else + fin.writeline cstr(strLine) + end if + next + fin.writeline "// **** End ****" + fin.close +next diff --git a/Chapter16/16-10_InitiateDDR_COM.vbs b/Chapter16/16-10_InitiateDDR_COM.vbs new file mode 100644 index 0000000..46e1549 --- /dev/null +++ b/Chapter16/16-10_InitiateDDR_COM.vbs @@ -0,0 +1,8 @@ +set mgr = CreateObject("CPApplet.CPAppletMgr") +set actions=mgr.GetClientActions +for each action in actions + if action.name="Discovery Data Collection Cycle" then + action.PerformAction + wscript.echo action.Name & " Initiated" + end if +next \ No newline at end of file diff --git a/Chapter16/16-11_InitiateFileCOLL.vbs b/Chapter16/16-11_InitiateFileCOLL.vbs new file mode 100644 index 0000000..30fb101 --- /dev/null +++ b/Chapter16/16-11_InitiateFileCOLL.vbs @@ -0,0 +1,9 @@ +Const FILECOLL = "{00000000-0000-0000-0000-000000000010}" +strComputer = "." + +Set objCCM = GetObject("winmgmts://" & strComputer & "/root/ccm") +Set objClient = objCCM.Get("SMS_Client") +Set objSched = objClient.Methods_("TriggerSchedule"). _ + inParameters.SpawnInstance_() +objSched.sScheduleID = FILECOLL +objCCM.ExecMethod "SMS_Client", "TriggerSchedule", objSched diff --git a/Chapter16/16-12_InitiateFileCOLL_COM.vbs b/Chapter16/16-12_InitiateFileCOLL_COM.vbs new file mode 100644 index 0000000..46e1549 --- /dev/null +++ b/Chapter16/16-12_InitiateFileCOLL_COM.vbs @@ -0,0 +1,8 @@ +set mgr = CreateObject("CPApplet.CPAppletMgr") +set actions=mgr.GetClientActions +for each action in actions + if action.name="Discovery Data Collection Cycle" then + action.PerformAction + wscript.echo action.Name & " Initiated" + end if +next \ No newline at end of file diff --git a/Chapter16/16-13_InitiateSWM.vbs b/Chapter16/16-13_InitiateSWM.vbs new file mode 100644 index 0000000..1160a9f --- /dev/null +++ b/Chapter16/16-13_InitiateSWM.vbs @@ -0,0 +1,9 @@ +Const SWM = "{00000000-0000-0000-0000-000000000022}" +strComputer = "." + +Set objCCM = GetObject("winmgmts://" & strComputer & "/root/ccm") +Set objClient = objCCM.Get("SMS_Client") +Set objSched = objClient.Methods_("TriggerSchedule"). _ + inParameters.SpawnInstance_() +objSched.sScheduleID = SWM +objCCM.ExecMethod "SMS_Client", "TriggerSchedule", objSched diff --git a/Chapter16/16-14_InitiateSWM_COM.vbs b/Chapter16/16-14_InitiateSWM_COM.vbs new file mode 100644 index 0000000..bfd1db8 --- /dev/null +++ b/Chapter16/16-14_InitiateSWM_COM.vbs @@ -0,0 +1,8 @@ +set mgr = CreateObject("CPApplet.CPAppletMgr") +set actions=mgr.GetClientActions +for each action in actions + if action.name="Software Metering Usage Report Cycle" then + action.PerformAction + wscript.echo action.Name & " Initiated" + end if +next \ No newline at end of file diff --git a/Chapter16/16-15_InitiateUserPol_COM.vbs b/Chapter16/16-15_InitiateUserPol_COM.vbs new file mode 100644 index 0000000..ab02b4b --- /dev/null +++ b/Chapter16/16-15_InitiateUserPol_COM.vbs @@ -0,0 +1,8 @@ +set mgr = CreateObject("CPApplet.CPAppletMgr") +set actions=mgr.GetClientActions +for each action in actions + if action.name="Request & Evaluate User Policy" then + action.PerformAction + wscript.echo action.Name & " Initiated" + end if +next \ No newline at end of file diff --git a/Chapter16/16-16_InitiateWIUpdate.vbs b/Chapter16/16-16_InitiateWIUpdate.vbs new file mode 100644 index 0000000..1889953 --- /dev/null +++ b/Chapter16/16-16_InitiateWIUpdate.vbs @@ -0,0 +1,8 @@ +Const WIU = “{00000000-0000-0000-0000-000000000032}” +strComputer = "2kPro" +Set objCCM = GetObject("winmgmts://" & strComputer & "/root/ccm") +Set objClient = objCCM.Get("SMS_Client") +Set objSched = objClient.Methods_("TriggerSchedule"). _ + inParameters.SpawnInstance_() +objSched.sScheduleID = WIU +objCCM.ExecMethod "SMS_Client", "TriggerSchedule", objSched diff --git a/Chapter16/16-17_InitiateWIUpdate_COM.vbs b/Chapter16/16-17_InitiateWIUpdate_COM.vbs new file mode 100644 index 0000000..8d9fdea --- /dev/null +++ b/Chapter16/16-17_InitiateWIUpdate_COM.vbs @@ -0,0 +1,8 @@ +set mgr = CreateObject("CPApplet.CPAppletMgr") +set actions=mgr.GetClientActions +for each action in actions + if action.name="MSI Product Source Update Cycle" then + action.PerformAction + wscript.echo action.Name & " Initiated" + end if +next diff --git a/Chapter16/16-18_InitiateClientRepair.vbs b/Chapter16/16-18_InitiateClientRepair.vbs new file mode 100644 index 0000000..b7d44a9 --- /dev/null +++ b/Chapter16/16-18_InitiateClientRepair.vbs @@ -0,0 +1,5 @@ +strComputer = "2kPro" +Set smsClient = GetObject("winmgmts://" & strComputer & _ + "/root/ccm:SMS_Client") +Set result = smsClient.ExecMethod_("RepairClient") +wscript.echo "Repair Initiated on " & strComputer diff --git a/Chapter16/16-19_InitiateClientRepair_CommandLine.vbs b/Chapter16/16-19_InitiateClientRepair_CommandLine.vbs new file mode 100644 index 0000000..a65b417 --- /dev/null +++ b/Chapter16/16-19_InitiateClientRepair_CommandLine.vbs @@ -0,0 +1,6 @@ +Set objArgs = WScript.Arguments +StrComputer = objArgs(0) +Set smsClient = GetObject("winmgmts://" & strComputer & _ + "/root/ccm:SMS_Client") +Set result = smsClient.ExecMethod_("RepairClient") +wscript.echo "Repair Initiated on " & strComputerName diff --git a/Chapter16/16-1_GetClientComponents_COM.vbs b/Chapter16/16-1_GetClientComponents_COM.vbs new file mode 100644 index 0000000..b9d8688 --- /dev/null +++ b/Chapter16/16-1_GetClientComponents_COM.vbs @@ -0,0 +1,15 @@ +Set oCPAppletMgr=CreateObject("CPApplet.CPAppletMgr") +Set oClientComponents=oCPAppletMgr.GetClientComponents +For Each oClientComponent In oClientComponents + strInfo = oClientComponent.DisplayName + Select Case oClientComponent.State + Case 0 + strInfo = strInfo & vbTAB & "(Installed)" + Case 1 + strInfo = strInfo & vbTAB & "(Enabled)" + Case 2 + strInfo = strInfo & vbTAB & "(Disabled)" + End Select + strinfo = strInfo & vbTAB & oClientcomponent.Version + wscript.echo strInfo +Next diff --git a/Chapter16/16-20_GetAssignedSite.vbs b/Chapter16/16-20_GetAssignedSite.vbs new file mode 100644 index 0000000..a4e0b5c --- /dev/null +++ b/Chapter16/16-20_GetAssignedSite.vbs @@ -0,0 +1,6 @@ +strComputerName = "." +Set smsClient = GetObject("winmgmts://" & strComputerName & _ + "/root/ccm:SMS_Client") +Set result = smsClient.ExecMethod_("GetAssignedSite") +WScript.Echo "Client is currently assigned to site " & _ + result.sSiteCode diff --git a/Chapter16/16-21_GetAssignedSite_COM.vbs b/Chapter16/16-21_GetAssignedSite_COM.vbs new file mode 100644 index 0000000..aaa2100 --- /dev/null +++ b/Chapter16/16-21_GetAssignedSite_COM.vbs @@ -0,0 +1,3 @@ +Set smsClient = CreateObject("Microsoft.SMS.Client") +WScript.Echo "Client is currently assigned to site " & _ + smsClient.GetAssignedSite diff --git a/Chapter16/16-22_DiscoverAssignedSite.vbs b/Chapter16/16-22_DiscoverAssignedSite.vbs new file mode 100644 index 0000000..7ec8ac6 --- /dev/null +++ b/Chapter16/16-22_DiscoverAssignedSite.vbs @@ -0,0 +1,11 @@ +'Requires a restart of the SMS Agent Host Service +strComputerName = "2kPro" +Set objWMIService = GetObject("winmgmts://" & _ + strComputerName & "/root/ccm") +Set objSMSClient = objWMIService.ExecQuery _ + ("Select * from SMS_Client") + +for each objClient in objSMSClient + objClient.EnableAutoAssignment = 1 + objClient.Put_ 0 +next \ No newline at end of file diff --git a/Chapter16/16-23_DiscoverAssignedSite_COM.vbs b/Chapter16/16-23_DiscoverAssignedSite_COM.vbs new file mode 100644 index 0000000..84f6cfe --- /dev/null +++ b/Chapter16/16-23_DiscoverAssignedSite_COM.vbs @@ -0,0 +1,3 @@ +Set SMSClient = CreateObject("Microsoft.SMS.Client") +WScript.Echo "Client is now assigned to " & _ + SMSClient.ReAssignSite diff --git a/Chapter16/16-24_SetAssignedSite.vbs b/Chapter16/16-24_SetAssignedSite.vbs new file mode 100644 index 0000000..38e44f3 --- /dev/null +++ b/Chapter16/16-24_SetAssignedSite.vbs @@ -0,0 +1,23 @@ +strComputer = "2kPro" +strSMSSite = "XXX" +Set objSMS = GetObject("winmgmts://" & strComputer & _ + "/root/ccm") +Set objSMSClient = objSMS.Get("SMS_Client") +set objParams = objSMSClient.Methods_("SetAssignedSite"). _ + inParameters.SpawnInstance_() +objParams.sSiteCode = strSMSSite +objSMS.ExecMethod _ + "SMS_Client", "SetAssignedSite", objParams + + + + +' sSiteCode = "XXX" + +' sMachine = "." + +' Set oCCMNamespace = GetObject("winmgmts:{impersonationLevel=impersonate}//" & sMachine & "/root/ccm") + +' Set smsClient = oCCMNamespace.Get("SMS_Client") + +' smsClient.SetAssignedSite sSiteCode, oParams diff --git a/Chapter16/16-26_GetCacheSize.vbs b/Chapter16/16-26_GetCacheSize.vbs new file mode 100644 index 0000000..141d97d --- /dev/null +++ b/Chapter16/16-26_GetCacheSize.vbs @@ -0,0 +1,10 @@ +'Requires a restart of the SMS Agent Host Service +strComputer = "2kpro" +Set objSMS = _ + GetObject("winmgmts:{impersonationLevel=impersonate}!//" & _ + strComputer & "/root/ccm/SoftMgmtAgent") +Set objCacheConfig = objSMS.ExecQuery _ + ("Select * from CacheConfig") +for each objCache in objCacheConfig + wscript.echo objCache.Size +next diff --git a/Chapter16/16-27_GetCacheSize_COM.vbs b/Chapter16/16-27_GetCacheSize_COM.vbs new file mode 100644 index 0000000..a9fb81c --- /dev/null +++ b/Chapter16/16-27_GetCacheSize_COM.vbs @@ -0,0 +1,4 @@ +Set oUIResource = CreateObject("UIResource.UIResourceMgr") +Set objCacheInfo = oUIResource.GetCacheInfo +wscript.echo objCacheInfo.TotalSize + diff --git a/Chapter16/16-28_SetCacheSize.vbs b/Chapter16/16-28_SetCacheSize.vbs new file mode 100644 index 0000000..ddfdbe6 --- /dev/null +++ b/Chapter16/16-28_SetCacheSize.vbs @@ -0,0 +1,11 @@ +'Requires a restart of the SMS Agent Host Service +strComputer = "2kpro" +Set objSMS = _ + GetObject("winmgmts:{impersonationLevel=impersonate}!//" & _ + strComputer & "/root/ccm/SoftMgmtAgent") +Set objCacheConfig = objSMS.ExecQuery _ + ("Select * from CacheConfig") +for each objCache in objCacheConfig + objCache.Size = 25 + objCache.Put_ 0 +next diff --git a/Chapter16/16-29_SetCacheSize_COM.vbs b/Chapter16/16-29_SetCacheSize_COM.vbs new file mode 100644 index 0000000..826fda7 --- /dev/null +++ b/Chapter16/16-29_SetCacheSize_COM.vbs @@ -0,0 +1,4 @@ +Set oUIResource = CreateObject("UIResource.UIResourceMgr") +Set objCacheInfo = oUIResource.GetCacheInfo +objCacheInfo.TotalSize = 15 + diff --git a/Chapter16/16-2_GetClientComponents.vbs b/Chapter16/16-2_GetClientComponents.vbs new file mode 100644 index 0000000..03364a8 --- /dev/null +++ b/Chapter16/16-2_GetClientComponents.vbs @@ -0,0 +1,8 @@ +strComputerName = "." +Set objSMS = GetObject("winmgmts://" & strComputerName & _ + "/root/ccm") +Set objSMSComponents = objSMS.ExecQuery _ + ("Select * from CCM_InstalledComponent") +for each objComponent in objSMSComponents + wscript.echo objComponent.Name & vbTAB & objComponent.Version +next \ No newline at end of file diff --git a/Chapter16/16-30_RerunAdvert.vbs b/Chapter16/16-30_RerunAdvert.vbs new file mode 100644 index 0000000..cfdcf4b --- /dev/null +++ b/Chapter16/16-30_RerunAdvert.vbs @@ -0,0 +1,43 @@ +strComputerName = "2KPro" +strAdvID = "LAB20001" +set objSMS = GetObject("winmgmts://" & _ + strComputerName & _ + "/root/ccm/policy/machine/actualconfig") +Set objScheds = objSMS.ExecQuery _ + ("select * from CCM_Scheduler_ScheduledMessage") +For each objSched in objScheds + 'locate ScheduleMessageID that contains strAdvID + If Instr(objSched.ScheduledMessageID, strAdvID) > 0 then + strMsgID = objSched.ScheduledMessageID + exit for + End If +Next +'strMsgID now contains proper Advertisement + +Set objSWDs = objSMS.ExecQuery _ +("select * from CCM_SoftwareDistribution where " & _ + "ADV_AdvertisementID = '" & strAdvID & "'" ) +for each objSWD in objSWDs + strOrigBehavior = objSWD.ADV_RepeatRunBehavior + 'strOrigBehavior now contains original Repeat Behavior + 'Now temporarily set RepeatRunBehavior to RerunAlways + objSWD.ADV_RepeatRunBehavior = "RerunAlways" + objSWD.Put_ 0 +Next + +set objCCM = GetObject("winmgmts://" & strComputerName & _ + "/root/ccm") +Set objSMSClient = objCCM.Get("SMS_Client") +objSMSClient.TriggerSchedule strMsgID + +'sleep for 5 seconds, for advert to start +wscript.sleep 5000 + +Set objScheds = objSMS.ExecQuery _ +("select * from CCM_SoftwareDistribution where " & _ + "ADV_AdvertisementID = '" & strAdvID & "'" ) +for each objSched in objScheds + 'Set RepeatRunBehavior back to original config + objSched.ADV_RepeatRunBehavior = strOrigBehavior + objSched.Put_ 0 +Next \ No newline at end of file diff --git a/Chapter16/16-31_RerunAdvert_COM.vbs b/Chapter16/16-31_RerunAdvert_COM.vbs new file mode 100644 index 0000000..ce52b53 --- /dev/null +++ b/Chapter16/16-31_RerunAdvert_COM.vbs @@ -0,0 +1,9 @@ +Set uiResource = CreateObject("UIResource.UIResourceMgr") +Set programList = uiResource.GetAvailableApplications +For each p in programList + wscript.echo p.Name + If p.Name = "SMS 2003 SDK V3" then + uiResource.ExecuteProgram p.ID, p.PackageID, True + Exit For + End if +Next diff --git a/Chapter16/16-32_GetCurrentMP_PMP.vbs b/Chapter16/16-32_GetCurrentMP_PMP.vbs new file mode 100644 index 0000000..e3da881 --- /dev/null +++ b/Chapter16/16-32_GetCurrentMP_PMP.vbs @@ -0,0 +1,18 @@ +strComputerName = "2kPro" +Set objSMS = GetObject("winmgmts://" & strComputerName & _ + "/root/ccm") +Set objAuthority = objSMS.ExecQuery _ + ("Select * from SMS_Authority") + +For Each authority In objAuthority + wscript.echo "SMS Site: " & _ + Replace(authority.Name, "SMS:", "") + wscript.echo "MP: " & authority.CurrentManagementPoint +Next + +Set colProxyMPs = objSMS.ExecQuery _ + ("Select * from SMS_MPProxyInformation") +For Each objProxyMP in colProxyMPs + wscript.echo "Proxy MP: " & objProxyMP.Name +Next + diff --git a/Chapter16/16-33_DisplayLastHWSWInvDates.vbs b/Chapter16/16-33_DisplayLastHWSWInvDates.vbs new file mode 100644 index 0000000..3b4c608 --- /dev/null +++ b/Chapter16/16-33_DisplayLastHWSWInvDates.vbs @@ -0,0 +1,40 @@ +strComputerName = "." + +'first, get the time zone bias +Set objWMIService = GetObject("winmgmts:\\" & strComputerName & _ + "\root\cimv2") +Set colTimeZone = objWMIService.ExecQuery _ + ("Select * from Win32_TimeZone") +For Each objTimeZone in colTimeZone + intBias = cint(objTimeZone.Bias ) +Next + +Set objSMS = GetObject("winmgmts://" & strComputerName & _ + "/root/ccm/invagt") +Set colInvInfo = objSMS.ExecQuery _ + ("Select * from InventoryActionStatus") + +for each objInvInfo in colInvInfo + + select case objInvInfo.InventoryActionID + case "{00000000-0000-0000-0000-000000000001}" + strInv = "Hardware Inventory" + case "{00000000-0000-0000-0000-000000000002}" + strInv = "Software Inventory" + case "{00000000-0000-0000-0000-000000000010}" + strInv = "File Collection" + case "{00000000-0000-0000-0000-000000000003}" + strInv = "Discovery Data Record" + end select + wscript.echo strInv & vbTAB & _ + convDate(objInvInfo.LastCycleStartedDate, intBias) & _ + vbTAB & convDate(objInvInfo.LastReportDate, intBias) +next + +Function convDate(dtmInstallDate, intBias) + convDate = CDate(Mid(dtmInstallDate, 5, 2) & "/" & _ + Mid(dtmInstallDate, 7, 2) & "/" & Left(dtmInstallDate, 4) _ + & " " & Mid (dtmInstallDate, 9, 2) & ":" & _ + Mid(dtmInstallDate, 11, 2) & ":" & Mid(dtmInstallDate, 13, 2)) + convDate = DateAdd("N",intBias,convDate) +End Function diff --git a/Chapter16/16-34_DisplayAdverts.vbs b/Chapter16/16-34_DisplayAdverts.vbs new file mode 100644 index 0000000..150a7ec --- /dev/null +++ b/Chapter16/16-34_DisplayAdverts.vbs @@ -0,0 +1,18 @@ +strComputer = "." +Set objSMS = GetObject("winmgmts:\\" & strComputer & _ + "\root\ccm\Policy\Machine\ActualConfig") +Set colSW = objSMS.ExecQuery _ + ("Select * from CCM_SoftwareDistribution") +wscript.echo colSW.count & " Advertisements" +for each oSW in colSW + wscript.echo oSW.PRG_HistoryLocation & vbTAB & _ + oSW.ADV_AdvertisementID & vbTAB & oSW.PKG_PackageID & _ + vbTAB & oSW.PRG_ProgramID & vbTAB & _ + oSW.ADV_ActiveTime & vbTAB & oSW.ADV_ExpirationTime & _ + vbTAB & oSW.ADV_MandatoryAssignments & vbTAB & _ + oSW.PKG_Name & vbTAB & oSW.PRG_ProgramName & vbTAB & _ + oSW.PRG_PRF_AfterRunning & vbTAB & _ + oSW.PRG_CustomLogoffReturnCodes & vbTAB & _ + oSW.PRG_MaxDuration & vbTAB & _ + oSW.PRG_PRF_UserLogonRequirement +next \ No newline at end of file diff --git a/Chapter16/16-35_DisplayAdverts_COM.vbs b/Chapter16/16-35_DisplayAdverts_COM.vbs new file mode 100644 index 0000000..0e82eca --- /dev/null +++ b/Chapter16/16-35_DisplayAdverts_COM.vbs @@ -0,0 +1,8 @@ +Set UI = CreateObject("UIResource.UIResourceMgr") +Set programList = UI.GetAvailableApplications + +For each program in programList + wscript.echo program.PackageID & vbTAB & program.ID & _ + vbTAB & program.Name & vbTAB & program.PackageName & _ + vbTAB & program.Version +Next diff --git a/Chapter16/16-36_DisplayRunningAdverts.vbs b/Chapter16/16-36_DisplayRunningAdverts.vbs new file mode 100644 index 0000000..a83046d --- /dev/null +++ b/Chapter16/16-36_DisplayRunningAdverts.vbs @@ -0,0 +1,10 @@ +strComputer = "." +Set objSMS = GetObject("winmgmts://" & strComputer & _ + "/root/ccm/SoftMgmtAgent") +Set colER = objSMS.ExecQuery _ + ("Select * from CCM_ExecutionRequest") +for each oER in colER + wscript.echo oER.ProgramID & vbTAB & oER.State & vbTAB & _ + oER.ProcessID & vbTAB & oER.AdvertID & vbTAB & _ + oER.IsAdminContext +next \ No newline at end of file diff --git a/Chapter16/16-37_DisplayAdvertHistory.vbs b/Chapter16/16-37_DisplayAdvertHistory.vbs new file mode 100644 index 0000000..b31356f --- /dev/null +++ b/Chapter16/16-37_DisplayAdvertHistory.vbs @@ -0,0 +1,49 @@ +Const HKEY_LOCAL_MACHINE = &H80000002 +' Only show adverts that have occurred within the last 90 days +Const intMaxDays = 90 +strComputer = "." + +'this is the base key path +strKeyPath = "SOFTWARE\Microsoft\SMS\Mobile Client\" & _ + "Software Distribution\Execution History\System" +'connect to the registry provider +Set oReg=GetObject _ + ("winmgmts:{impersonationLevel=impersonate}!\\" & _ + strComputer & "\root\default:StdRegProv") + +oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys + +'this first for-each loop is used to enumerate each package +' key +For Each PackageID In arrSubKeys + oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath & "\" & _ + PackageID, arrSubKeys2 + 'the second for-each loop is used to enumerate each + ' GUID key within a package key + For Each GUID in arrSubKeys2 + SearchStrKeyPath = strKeyPath & "\" & PackageID & _ + "\" & GUID + oReg.GetStringValue HKEY_LOCAL_MACHINE, _ + SearchStrKeyPath, "_ProgramID", strProgramID + oReg.GetStringValue HKEY_LOCAL_MACHINE, _ + SearchStrKeyPath, "_RunStartTime", strRunStartTime + oReg.GetStringValue HKEY_LOCAL_MACHINE, _ + SearchStrKeyPath, "_State", strState + oReg.GetStringValue HKEY_LOCAL_MACHINE, _ + SearchStrKeyPath, "SuccessOrFailureCode", _ + strSuccessOrFailure + oReg.GetStringValue HKEY_LOCAL_MACHINE, _ + SearchStrKeyPath, "SuccessOrFailureReason", _ + strSuccessOrFailureReason + + 'Only display data for advert starts < 90 days + If not DateDiff _ + ("d",strRunStartTime, now()) > intMaxDays Then + wscript.echo strProgramID & vbTAB & _ + strRunStartTime & vbTAB & strState & vbTAB & _ + strSuccessOrFailure & vbTAB & _ + strSuccessOrFailureReason + End If + Next +Next + diff --git a/Chapter16/16-3_ForceHardwareInv.vbs b/Chapter16/16-3_ForceHardwareInv.vbs new file mode 100644 index 0000000..f5507a1 --- /dev/null +++ b/Chapter16/16-3_ForceHardwareInv.vbs @@ -0,0 +1,18 @@ +Const HWINV = "{00000000-0000-0000-0000-000000000001}" +strComputer = "." + +FullInv = Msgbox("Full Inventory?", vbYesNo) + +If FullInv = vbYes then + Set objSMS = GetObject("winmgmts://" & strComputer & _ + "/root/ccm/invagt") + objSMS.Delete "InventoryActionStatus.InventoryActionID=" _ + & Chr(34) & HWINV & Chr(34) +End If + +Set objCCM = GetObject("winmgmts://" & strComputer & "/root/ccm") +Set objClient = objCCM.Get("SMS_Client") +Set objSched = objClient.Methods_("TriggerSchedule"). _ + inParameters.SpawnInstance_() +objSched.sScheduleID = HWINV +objCCM.ExecMethod "SMS_Client", "TriggerSchedule", objSched diff --git a/Chapter16/16-4_ForceHardwareInv_COM.vbs b/Chapter16/16-4_ForceHardwareInv_COM.vbs new file mode 100644 index 0000000..85997eb --- /dev/null +++ b/Chapter16/16-4_ForceHardwareInv_COM.vbs @@ -0,0 +1,8 @@ +set mgr = CreateObject("CPApplet.CPAppletMgr") +set actions=mgr.GetClientActions +for each action in actions + if action.name="Hardware Inventory Collection Cycle" then + action.PerformAction + wscript.echo action.Name & " Initiated" + end if +next \ No newline at end of file diff --git a/Chapter16/16-5_ForceSoftwareInv.vbs b/Chapter16/16-5_ForceSoftwareInv.vbs new file mode 100644 index 0000000..edf8de8 --- /dev/null +++ b/Chapter16/16-5_ForceSoftwareInv.vbs @@ -0,0 +1,18 @@ +Const SWINV = "{00000000-0000-0000-0000-000000000002}" +strComputer = "." + +FullInv = Msgbox("Full Inventory?", vbYesNo) + +If FullInv = vbYes then + Set objSMS = GetObject("winmgmts://" & strComputer & _ + "/root/ccm/invagt") + objSMS.Delete "InventoryActionStatus.InventoryActionID=" _ + & Chr(34) & SWINV & Chr(34) +End If + +Set objCCM = GetObject("winmgmts://" & strComputer & "/root/ccm") +Set objClient = objCCM.Get("SMS_Client") +Set objSched = objClient.Methods_("TriggerSchedule"). _ + inParameters.SpawnInstance_() +objSched.sScheduleID = HWINV +objCCM.ExecMethod "SMS_Client", "TriggerSchedule", objSched diff --git a/Chapter16/16-6_SoftwareInv_COM.vbs b/Chapter16/16-6_SoftwareInv_COM.vbs new file mode 100644 index 0000000..68a6353 --- /dev/null +++ b/Chapter16/16-6_SoftwareInv_COM.vbs @@ -0,0 +1,8 @@ +set mgr = CreateObject("CPApplet.CPAppletMgr") +set actions=mgr.GetClientActions +for each action in actions + if action.name="Software Inventory Collection Cycle" then + action.PerformAction + wscript.echo action.Name & " Initiated" + end if +next \ No newline at end of file diff --git a/Chapter16/16-7_RefreshMachinePolicy.vbs b/Chapter16/16-7_RefreshMachinePolicy.vbs new file mode 100644 index 0000000..12c177f --- /dev/null +++ b/Chapter16/16-7_RefreshMachinePolicy.vbs @@ -0,0 +1,9 @@ +Const MachinePol = "{00000000-0000-0000-0000-000000000021}" +strComputer = "2kPro" + +Set objCCM = GetObject("winmgmts://" & strComputer & "/root/ccm") +Set objClient = objCCM.Get("SMS_Client") +Set objSched = objClient.Methods_("TriggerSchedule"). _ + inParameters.SpawnInstance_() +objSched.sScheduleID = MachinePol +objCCM.ExecMethod "SMS_Client", "TriggerSchedule", objSched diff --git a/Chapter16/16-8_RefreshAndEvalMachinePolicy_COM.vbs b/Chapter16/16-8_RefreshAndEvalMachinePolicy_COM.vbs new file mode 100644 index 0000000..f5980b2 --- /dev/null +++ b/Chapter16/16-8_RefreshAndEvalMachinePolicy_COM.vbs @@ -0,0 +1,8 @@ +set mgr = CreateObject("CPApplet.CPAppletMgr") +set actions=mgr.GetClientActions +for each action in actions + if action.name="Request & Evaluate Machine Policy" then + action.PerformAction + wscript.echo action.Name & " Initiated" + end if +next \ No newline at end of file diff --git a/Chapter16/16-9_InitiateDDR.vbs b/Chapter16/16-9_InitiateDDR.vbs new file mode 100644 index 0000000..121fdf9 --- /dev/null +++ b/Chapter16/16-9_InitiateDDR.vbs @@ -0,0 +1,9 @@ +Const DDR = "{00000000-0000-0000-0000-000000000003}" +strComputer = "." + +Set objCCM = GetObject("winmgmts://" & strComputer & "/root/ccm") +Set objClient = objCCM.Get("SMS_Client") +Set objSched = objClient.Methods_("TriggerSchedule"). _ + inParameters.SpawnInstance_() +objSched.sScheduleID = DDR +objCCM.ExecMethod "SMS_Client", "TriggerSchedule", objSched diff --git a/Chapter16/16_25_SetAssignedSite_Adv.vbs b/Chapter16/16_25_SetAssignedSite_Adv.vbs new file mode 100644 index 0000000..865a7dc --- /dev/null +++ b/Chapter16/16_25_SetAssignedSite_Adv.vbs @@ -0,0 +1,14 @@ +strComputerName = "." +Set smsClient = GetObject("winmgmts://" & strComputerName & "/root/ccm:SMS_Client") + +Set result = smsClient.ExecMethod_("GetAssignedSite") +WScript.Echo "Client is currently assigned to site " & result.sSiteCode + +Set inParam = smsClient.Methods_.Item("SetAssignedSite").inParameters.SpawnInstance_() +inParam.sSiteCode = "LAB" +Set result = smsClient.ExecMethod_("SetAssignedSite", inParam) + +Set result = smsClient.ExecMethod_("GetAssignedSite") +WScript.Echo "Client is now assigned to " & result.sSiteCode + + diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..636dda0 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,27 @@ +Freeware License, some rights reserved + +Copyright (c) 2006 Greg Ramsey and Warren Byle + +Permission is hereby granted, free of charge, to anyone obtaining a copy +of this software and associated documentation files (the "Software"), +to work with the Software within the limits of freeware distribution and fair use. +This includes the rights to use, copy, and modify the Software for personal use. +Users are also allowed and encouraged to submit corrections and modifications +to the Software for the benefit of other users. + +It is not allowed to reuse, modify, or redistribute the Software for +commercial use in any way, or for a user’s educational materials such as books +or blog articles without prior permission from the copyright holder. + +The above copyright notice and this permission notice need to be included +in all copies or substantial portions of the software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..b4aaf9f --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +#Apress Source Code + +This repository accompanies [*SMS 2003 Recipes*](http://www.apress.com/9781590597125) by Greg Ramsey and Warren Byle (Apress, 2006). + +![Cover image](9781590597125.jpg) + +Download the files as a zip using the green button, or clone the repository to your machine using Git. + +##Releases + +Release v1.0 corresponds to the code in the published book, without corrections or updates. + +##Contributions + +See the file Contributing.md for more information on how you can contribute to this repository. diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..28d5e22 --- /dev/null +++ b/README.txt @@ -0,0 +1 @@ +No additional information is required for these scripts. \ No newline at end of file diff --git a/contributing.md b/contributing.md new file mode 100644 index 0000000..f6005ad --- /dev/null +++ b/contributing.md @@ -0,0 +1,14 @@ +# Contributing to Apress Source Code + +Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers. + +## How to Contribute + +1. Make sure you have a GitHub account. +2. Fork the repository for the relevant book. +3. Create a new branch on which to make your change, e.g. +`git checkout -b my_code_contribution` +4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted. +5. Submit a pull request. + +Thank you for your contribution! \ No newline at end of file