Powershell script to change Windows 7 Libraries

Answered Powershell script to change Windows 7 Libraries

  • Thursday, May 12, 2011 1:17 PM
     
     
    How can I use powershell to remove or add known folders from a library-ms XML file? A login script to remove the <searchConnectorDescription> element that contains the <url>knownfolder might do the trick. I rather avoid loading 3rd party modules if possible. Thanks!

All Replies

  • Friday, May 13, 2011 7:50 PM
     
     Answered

    This seems to work.

     

    #Array of known folder GUIDs (Public)
    [array]$KnownFldrs = "knownfolder:{DFDF76A2-C82A-4D63-906A-5644AC457385}","knownfolder:{C4AA340D-F20F-4863-AFEF-F87EF2E6BA25}","knownfolder:{ED4824AF-DCE4-45A8-81E2-FC7965083634}","knownfolder:{3d644c9b-1fb8-4f30-9b45-f670235f79c0}","knownfolder:{debf2536-e1a8-4c59-b6a2-414586476aea}","knownfolder:{3214FAB5-9757-4298-BB61-92A9DEAA44FF}","knownfolder:{B6EBFB86-6907-413C-9AF7-4FC2ABF07CC5}","knownfolder:{E555AB60-153B-4D17-9F04-A5FE99FC15EC}","knownfolder:{2400183A-6185-49FB-A2D8-4A392A602BA3}"
    #library folder location and files
    $folder = "$env:appdata\Microsoft\Windows\Libraries"
    $files = get-childitem $folder\*.library-ms
    #loop through library files
    foreach ($file in $files)
    {
    #create and load XML object
        $xml = New-Object xml
        $xml.Load($file.fullname)
        $items = ($xml.libraryDescription.searchConnectorDescriptionList.searchConnectorDescription)
    #loop through XML elements
            foreach ($item in $items)
            {
    #remove the known folder from the library
                If ($KnownFldrs -match $item.SimpleLocation.url)
                    {
                    $xml.libraryDescription.searchConnectorDescriptionList.removechild($item)
                    }
            }
    #save library file
            $xml.save($file.fullname)
    }

    • Marked As Answer by tomcomtech_ Friday, May 13, 2011 7:55 PM
    •