Remove multiple package (with script?)

Author Message
knowme

  • Total Posts : 28
  • Scores: 0
  • Reward points : 25210
  • Joined: 6/27/2007
  • Status: offline
Remove multiple package (with script?) Friday, January 13, 2012 7:41 AM (permalink)
0
[Helpful answer received] / [List Solutions Only]
Hi
We need to delete multiple old packages in the sccm console.
Using the delete wizzard is very painfull when you have many packages.
I was thinking if someone have a powershell script that can delete all packages taken from a csv file containing the packageID?
Or any other good idea to solve our problem? :-)
 
 
 
#1
    skissinger

    • Total Posts : 4807
    • Scores: 458
    • Reward points : 105260
    • Joined: 9/13/2001
    • Location: Sherry Kissinger
    • Status: offline
    Re:Remove multiple package (with script?) Friday, January 13, 2012 10:19 AM (permalink)
    0
    [This post was marked as helpful]
    Do you have SMS2003 recipes?  (the book).  Example 4-4 is a vbscript  to Delete a package.  One for/next loop and feed in a line by line from a text file, and you'll have it.
    mofmaster@myitforum.com
    My Blog
    Microsoft MVP - ConfigMgr
     
    #2
      knowme

      • Total Posts : 28
      • Scores: 0
      • Reward points : 25210
      • Joined: 6/27/2007
      • Status: offline
      Re:Remove multiple package (with script?) Monday, January 16, 2012 2:48 AM (permalink)
      0
      skissinger


      Do you have SMS2003 recipes?  (the book).  Example 4-4 is a vbscript  to Delete a package.  One for/next loop and feed in a line by line from a text file, and you'll have it.


      Thanks Sherry, looks like a nice and simple solution, will try that :-)
       
      #3
        knowme

        • Total Posts : 28
        • Scores: 0
        • Reward points : 25210
        • Joined: 6/27/2007
        • Status: offline
        Re:Remove multiple package (with script?) Monday, January 16, 2012 7:10 AM (permalink)
        0
        [This post was marked as helpful]
        This is how I solved it.
        Using the script from SMS 2003 Recipes and just add code to import from a csv-file I was able to do the removal. The code for the script can be found below.
         
        Thanks Sherry for the tip about the script in book :-)
         
        ' -------------------------------------------------------------------------------------------------- 
        '
        ' Edit the line with strSMSServer with your SCCM server hostname.
        ' Create a csv file with all the packageID:s you wants to remove, seperate them with a semicolon.
        ' Run the Delete_Packages.vbs
        '
        ' Remove the ' from " 'wscript.echo "Deleted " & strPackageID " if you want to display a messagebox
        '
        ' --------------------------------------------------------------------------------------------------
        dim fs,objTextFile 
        set fs=CreateObject("Scripting.FileSystemObject")
        dim arrStr
        dim x
        dim y
        x = 0
        y = 0
        set objTextFile = fs.OpenTextFile("delete_packages.csv")
        Do while NOT objTextFile.AtEndOfStream 
        arrStr = split(objTextFile.ReadLine,";")
        Loop
        objTextFile.Close 
        set objTextFile = Nothing
        set fs = Nothing
        For Each package In arrStr 
        strSMSServer = "SCCMSERVER"
        on error resume next
        strPackageID = package
        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
        Next
         
        #4
          Online Bookmarks Sharing: Share/Bookmark

          Jump to:

          Current active users

          There are 0 members and 1 guests.

          Icon Legend and Permission

          • New Messages
          • No New Messages
          • Hot Topic w/ New Messages
          • Hot Topic w/o New Messages
          • Locked w/ New Messages
          • Locked w/o New Messages
          • Read Message
          • Post New Thread
          • Reply to message
          • Post New Poll
          • Submit Vote
          • Post reward post
          • Delete my own posts
          • Delete my own threads
          • Rate post

          2000-2013 ASPPlayground.NET Forum Version 3.9