Tuesday, July 12, 2011

How to remove locks on packages in distribution points list for a package


Sometimes you see lock on a DP for a particular package. This generally happens after a migration, or incorrectly creating a package.

To fix this, run the below query on your central database:

UPDATE Pkgservers set SourceSite = 'central site code' where PkgID = 'package id' and SiteCode = 'XXX'

Monday, July 11, 2011

Script to remove the list of packages from DPs in SCCM

' Pratik Pawar
' This script will remove the packages given in text file listofpackagesToDelete.txt to that DP


Option Explicit
'On Error Resume Next

Dim objFSO
Dim objTextFile
Dim strNextLine
Dim arrServiceList

Dim WbemServices
Dim loc

Dim DPs, DP

Set loc = CreateObject("WbemScripting.SWbemLocator")
Set WbemServices = loc.ConnectServer( , "root\SMS\site_999")

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("listofpackagesToDelete.txt", ForReading)


Do Until objTextFile.AtEndOfStream
    'read the next line
    strNextLine = objTextFile.Readline
    arrServiceList = Split(strNextLine , "    ")

    'arrServiceList(0) = packageid, arrServiceList(1) = DP

    Set DPs = wbemServices.ExecQuery("Select * From SMS_DistributionPoint WHERE PackageID='" & arrServiceList(0) & "' AND SiteCode = '" & arrServiceList(1) & "'")

    For Each DP In DPs
        Wscript.Echo  DP.ServerNALPath
        DP.Delete_
    Next
Loop

Friday, May 27, 2011

SCCM Queries for AD objects

Here are some queries for filtering on AD objects like Ad Site or AD OU:

1. Query for a single organizational unit:

select * from SMS_R_System where SystemOUName = "ABC1.ABC.YOURDOMAIN.COM/ OUNAME / OUNAME / OUNAME /WORKSTATIONS/STANDARD"

2. Query for multiple organizational units:

select * from SMS_R_System where SystemOUName in ( "ABC1.ABC. YOURDOMAIN.COM/OUNAME/OUNAME/OUNAME/OUNAME/WORKSTATIONS", "XX.XX. YOURDOMAIN.COM/NAME/OUNAME/OUNAME/WORKSTATIONS" )

3. Query for a single Active Directory Site:

select * from SMS_R_System where ADSiteName = "Default-First-Site-Name"

4. Query for a multiple Active Directory Sites:

select * from SMS_R_System where ADSiteName in ( "Default-First-Site-Name", "Site-XXX" )

Thursday, May 12, 2011

error CWmi::Connect(): ConnectServer(Namespace) failed. - 0x8004100e in distmgr.log

If you see this error in distmgr.log on a secondary site DP, then take the following steps:

1. Windows server 2008 : Using Server manager, the the IIS 6 WMI Metabase compatibility feature and II6 WMI compatibility feature.

2. Windows server 2003 : Try to reinstall IIS, select all IIS components, ASP, Webdav, BITS etc and enable them in internet services manager. On the Central site console, uncheck the option "Use Bits to download packages from this DP". Wait for some time.

Tuesday, May 3, 2011

Reinstall IIS on a Secondary Site SCCM server

Original link:
http://blogs.technet.com/b/configurationmgr/archive/2009/08/12/configmgr-2007-how-to-properly-reinstall-iis-in-windows-server-2008-on-an-sccm-2007-site-system.aspx

ConfigMgr 2007: How to properly reinstall IIS in Windows Server 2008 on an SCCM 2007 site system



When you experience issues with your Windows Server 2008 Web Server (IIS) role, including 401, 403, or 500 errors in the IIS logs and MPControl.log, a Configuration Manager 2007 site system relying on the IIS system may also experience issues due to the various SCCM roles that rely on IIS functioning properly.
For various reasons it may ultimately be necessary to reinstall IIS in these situations, and listed below are the necessary steps that need to be taken to properly reinstall the Web Server (IIS) role on a Windows Server 2008 server that is hosting an SCCM 2007 site system.
1. Make sure that the server that IIS needs to be reinstalled on is strictly an SCCM 2007 site server and that you are not using any other applications, roles, or features that rely on IIS other than SCCM 2007 and any dependent applications or roles (such as WSUS or SQL Reporting Services). If the server is not strictly an SCCM 2007 site server, make sure that you will be able to reinstall those applications, roles, or features without losing settings, data, or functionality once IIS has been reinstalled. If you cannot do this or are unsure, do not proceed.
Please also note that while IIS is being reinstalled, the site server will be effectively down since no clients will be able to report up or retrieve policies. Any of the below roles that rely on IIS will also be down and not available, so ensure that the reinstall is done at a time when you can afford to have the server be down. This is usually not an issue though because usually when IIS needs to be reinstalled, it is not working properly and the server is effectively down anyways.
2. In the SCCM 2007 console under Site Settings - - > Site Systems, on the site server where IIS needs to be reinstalled, examine to see if any of the following roles that rely on IIS are installed:
  • ConfigMgr distribution point
  • ConfigMgr management point (MPSetup.log)
  • ConfigMgr reporting point (rsetup.log & SMSReportingInstall.log)
  • ConfigMgr software update point (SUPSetup.log)
  • ConfigMgr server locator point (SMSSLPSetup.log)
  • ConfigMgr fallback status point (SMSFSPSetup.log)
  • ConfigMgr Reporting Services Point (SRSRPSetup.log)
  • ConfigMgr state migration point (SMSSMPSetup.log)
If any of the above roles are installed, go into the properties of the role and make a note of the settings for the role.
For the ConfigMgr state migration point, make sure when noting the settings for the role to include where client state migration data is being backed up to before removing the role. As safety precaution, make sure to also note any encryption keys for any data that is currently on the state migration point. These keys can be obtained by going into the SCCM 2007 console and expanding the "Operating System Deployment" node, clicking on "Computer Association", right clicking on the associations, and selecting "View Recovery Information". Copy the name of the PC that the data is associated with, the user state store location, and the key.
Once you have noted the settings, uninstall any of the above roles EXCEPT for the ConfigMgr distribution point. DO NOT uninstall the ConfigMgr distribution point!
3.  Monitor the setup logs referenced in Step 2 and verify that all roles have been uninstalled successfully. The logs are normally found under C:\Program Files\Microsoft Configuration Manager\Logs, but can vary depending on your particular installation and environment.
4. If the server is also a ConfigMgr distribution point that uses BITS, in the properties of the ConfigMgr distribution point role, under the "General" tab, uncheck the option "Allow clients to transfer content from this distribution point using BITS, HTTP, and HTTPS (required for device clients and Internet-based clients)" to disable BITS and then click "Apply".
5.  If the server is also a ConfigMgr distribution point that is a multicast distribution point, in the properties of the ConfigMgr distribution point role, under the "Multicast" tab, uncheck the option "Enable multicast" and then click "Apply". Monitor the MCSetup.log to ensure that multicast is uninstalled successfully.
6.  If the server is also a ConfigMgr software update point and WSUS was installed on the server, uninstall WSUS either through the "Program and Features" Control Panel by selecting to uninstall "Microsoft Windows Server Update Services 3.0 SP1" or through Server Manager by removing the "Windows Server Update Services" role under the "Roles" node. Before uninstalling WSUS, make sure you have notate where the WSUS database is located. When uninstalling WSUS, make sure to specify NOT to remove the WSUS database.
7. If the server is also the SQL server for SCCM 2007, a ConfigMgr Reporting Services Point, and SQL Reporting Services Point was installed on the server, back up any custom reports and then uninstall SQL Reporting Services from the server via the SQL setup program.
8. In the "Programs and Features" Control Panel, uninstall "WebDAV 7.5 for IIS 7.0".
9. In Server Manager, under the "Features" node, remove the "Windows Process Activation Service" feature. Removing this feature will remove several roles and features that are dependent on this feature, including the "Web Server (IIS)" role and "BITS Server Extensions".
10. When prompted, restart the server.
11. When the server restarts and comes back up, log back in and rename the “inetpub” folder, usually found at the root level of the C: drive.
12. Follow the TechNet article on installing IIS in Windows Server 2008 to support an SCCM 2007 site system:
How to Configure Windows Server 2008 for Site Systems
13. If the server is also a ConfigMgr distribution point that uses BITS, in the properties of the ConfigMgr distribution point role, under the "General" tab, check the option "Allow clients to transfer content from this distribution point using BITS, HTTP, and HTTPS (required for device clients and Internet-based clients)." to enable BITS and then click "Apply".
14. If the server is also a ConfigMgr distribution point that is a multicast distribution point, in the properties of the ConfigMgr distribution point role, under the "Multicast" tab, check the option "Enable multicast" and then click "Apply". Monitor the MCSetup.log to ensure that multicast is reinstalled successfully.
15. If the server is also a ConfigMgr software update point and WSUS was installed on the server, reinstall Microsoft Windows Server Update Services 3.0 SP1 either through the standalone install executable found at:
Windows Server Update Services 3.0 SP1
or through Server Manager by adding the "Windows Server Update Services" role under the "Roles" node. Make sure to reattach to the existing WSUS database as notated in Step 6.
Also make sure to properly choose between the Default Web Site or the Custom Web Site. This can be determined by looking at the properties of the "Software Update Component" in the ConfigMgr 2007 console under Site Settings - - > Component Configuration. Under the "General" tab, if the Ports being used are 80/443, then chose the Default Web Site. If the ports being used are 8530/8531, then choose the Custom Web Site.
16. If the server is also the SQL server for SCCM 2007, a ConfigMgr Reporting Services Point, and SQL Reporting Services Point was installed on the server, reinstall SQL Reporting Services from the server via the SQL setup program. If needed, the below guides will walk you through setting up Reporting Services in R2:
Configuring SQL Reporting Services
Below is the link for the full documentation for SQL Reporting Services in Configuration Manager 2007 R2:
SQL Reporting Services in Configuration Manager 2007 R2

Once reinstallation is complete, restore any custom reports that were backed up in Step 7.
17. In the SCCM 2007 console under Site Settings - - > Site Systems, on the SCCM 2007 site server where IIS was reinstalled, reinstall the site roles that were uninstalled in Step 2. For the ConfigMgr state migration point, make sure to restore the settings that were captured in Step 2.
18. Monitor the setup logs as referenced in Step 2 and verify that all roles reinstall successfully.
19. If the server is a ConfigMgr software update point, run a full synchronization by going under the "Software Updates" node, right clicking on "Update Repository", and choosing "Run Synchronization".
NOTES:
1. Removing the ConfigMgr reporting point role should not delete or affect any custom reports. The reports should still exist when the role is reinstalled.
2. Removing the ConfigMgr software update point role should not delete or affect any settings under Component Configuration - - > Software Update Point Component. It should also not affect any updates, packages, lists, or templates that have already been set up under the "Software Updates" node.. The settings, packages, lists, and templates should all still exist when the role is reinstalled.
3. Removing the ConfigMgr state migration point role should not delete or affect any data that has been saved to the state migration point. All backed up data should still exist when the role is reinstalled. However, settings are not restored to their original values so make sure to capture the settings before removing the role as described in Step 2. Additionally, as a safety precaution, make sure to back up any encryption keys and paths as described in the notes of Step 2.
4. Packages on Distribution Points should not be affected and you should not need to repush packages to the Distribution Points after reinstalling IIS as long as the ConfigMgr distribution point role is NOT removed, so please make sure that the role is NOT removed or uninstalled. Simply disabling and then later enabling BITS and multicast will rebuild the necessary virtual directories in IIS that the Distribution Point relies on.



Wednesday, April 20, 2011

VBScript to get collection schedules

Option Explicit

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objLogFile : Set objLogFile = objFSO.CreateTextFile("Collections.log")

Dim strSourceServer
strSourceServer   = "XXX"
Dim strSourceSiteCode
strSourceSiteCode = "XXX"

Dim objSourceWMIService
Dim AllCollections
Dim objCollection
Dim strCollectionName
Dim strCollectionComment
Dim schedule
Dim schedtype
Dim bolScheduleAvailable
Dim strRecur
Dim strEvery

Set objSourceWMIService = GetObject("winmgmts://" & strSourceServer & "\root\sms\site_" & strSourceSiteCode)

'objLogFile.WriteLine Now & " start "

'Loop trought all collections exsisting on the source server
Set AllCollections = objSourceWMIService.ExecQuery("SELECT * FROM SMS_Collection WHERE NAME NOT LIKE 'All%' AND NAME NOT LIKE 'Root%'")

For Each objCollection In AllCollections
    strCollectionName    = objCollection.Name
    strCollectionComment = objCollection.Comment

    'objLogFile.WriteLine Now & " - Collection  " & objCollection.Name

    Set objCollection = objSourceWMIService.Get("SMS_Collection='" & objCollection.CollectionID & "'" )

    'Get Collection schedule
    On Error Resume Next
    Set schedule = objCollection.RefreshSchedule(0)

    On Error GoTo 0

    If Err.Number = 424 Then
        objLogFile.WriteLine "Collection has no Schedule  " & objCollection.Name
    ElseIf Err.Number <> 0 Then
        objLogFile.WriteLine "An Error (" & Err.Number & ") occured while getting the Update Schedule from " & objCollection.Name
    Else
        'On Error Resume Next
        schedtype = Schedule.Path_.Class

        Select Case (schedtype)
            Case "SMS_ST_RecurInterval"
                If schedule.MinuteSpan <> 0 Then strRecur = "Minute"
                If schedule.HourSpan <> 0 Then strRecur = "Hour"
                If schedule.DaySpan <> 0 Then strRecur = "Day"

                If schedule.MinuteDuration <> 0 Then strEvery = schedule.MinuteDuration
        If schedule.HourDuration <> 0 Then strEvery = schedule.HourDuration
        If schedule.DayDuration <> 0 Then strEvery = schedule.DayDuration

                    bolScheduleAvailable = True
                    objLogFile.WriteLine objCollection.Name & ",Recurr every " & strEvery & " " &  strRecur & ",Starting " & schedule.StartTime

                Case "SMS_ST_RecurWeekly"

                    If schedule.ForNumberOfWeeks <> 0 Then  strRecur = "Weekly"

                    bolScheduleAvailable = True
                    objLogFile.WriteLine objCollection.Name & ",Recurr every " & strRecur & ",Starting " & schedule.StartTime

                Case "SMS_ST_RecurMonthlyByDate"

            If schedule.ForNumberOfMonths <> 0 Then strRecur = "Monthly"
                    bolScheduleAvailable = True
                    objLogFile.WriteLine objCollection.Name & ",Recurr every " & strRecur & ",Starting " & schedule.StartTime
                Case "SMS_ST_RecurMonthlyByWeekday"

                    Token.StartTime = schedule.StartTime
                    objLogFile.WriteLine Now & " - SMS_ST_RecurMonthlyByWeekday Schedule available " & objCollection.Name

                    bolScheduleAvailable = True

                Case "SMS_ST_NonRecurring"

                    bolScheduleAvailable = True
                    objLogFile.WriteLine Now & " - SMS_ST_NonRecurring Schedule available " & objCollection.Name

                Case Else
                    bolScheduleAvailable = False
                    objLogFile.WriteLine Now & " - Unknown Schedule (skipping) " & objCollection.Name
            End Select

        End If

    Next

    objLogFile.WriteLine Now & " - Finish"
    WScript.Echo "Done"

Wednesday, April 6, 2011

VBScript Script to Delete Specific SCCM Collections and Associated Advertisements

'need to change the site code in line Set WbemServices = loc.ConnectServer( ,"root\SMS\site_XXX")
'script takes input from a text file collectionslist.txe, having collection names.

Option Explicit
On Error Resume Next

Dim loc

Dim Collection
Dim Collections
Dim strCollection
Dim strCollectionID

Dim Advertisement
Dim Advertisements
Dim objFSO
Dim objFile

Dim WbemServices
Const ForReading = 1

Set loc = CreateObject("WbemScripting.SWbemLocator")

Set WbemServices = loc.ConnectServer( ,"root\SMS\site_XXX")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("collectionslist.txt", ForReading)

Do Until objFile.AtEndOfStream
strCollection = objFile.ReadLine

    Set Collections = WbemServices.ExecQuery("select * from SMS_Collection where name like '%" & strCollection & "%'")

    For Each Collection In Collections
        strCollectionID = Collection.CollectionID
        Wscript.Echo "Collection    : " + Collection.Name

        Set Advertisements = WbemServices.ExecQuery("select * from SMS_Advertisement where CollectionID = """ & strCollectionID & """")
       
        For Each Advertisement in Advertisements
            Wscript.Echo "Advertisement : " & Advertisement.AdvertisementName
            Advertisement.Delete_
        Next
    On Error Goto 0
    Collection.Delete_
    Next
Loop
objFile.Close