Welcome to MSDN Blogs Sign in | Join | Help

Eric Kraus' SharePoint/.NET Blog

What the field says about MOSS.

News

  • Subscribe to this blog


    Eric Kraus on Live Messenger




      Disclaimer
      These postings are provided "AS IS" with no warranties and confer no rights. In addition, these postings are my own and do not represent the views of Microsoft.
    Packing up My Documents: A PowerShell Story

    I am frequently asked by colleagues and customers for a dump of all of my SharePoint content (presentations, white papers, etc.)  While I continue to add files like these to my hard drive in various different locations, it has started to take me a while to aggregate them all forward.  It dawned on me that this need not be a half an hour exercise of locating documents.

    Bing!  PowerShell

    Thanks to another colleagues blog:  http://blogs.msdn.com/daiken/archive/2007/02/12/compress-files-with-windows-powershell-then-package-a-windows-vista-sidebar-gadget.aspx

    I created a few functions and added them to my PowerShell module that loads with my profile.  Now it’s as simple as:


    Get-ChildItem -path c: -filter *sharepoint* -recurse | create-zip "c:\sharepoint.zip"

    #Special Thanks to: 
    # http://blogs.msdn.com/daiken/archive/2007/02/12/compress-files-with-windows-powershell-then-package-a-windows-vista-sidebar-gadget.aspx

    # Create a new zip file from pipeline
    function Create-Zip()
    {
        param
        (
            [string]$zipFile
        );
       
        New-Zip -zipfileName $zipFile
        $zip = Get-Zip -zipfileName $zipFile
       
        #loop through files in pipeline
        foreach($file in $input)
        {
            #add file to zip and sleep 1/2 second
            $zip.CopyHere($file.FullName)
            Start-sleep -milliseconds 500
        }

    }

    #create a new zip file
    function New-Zip
    {
        param([string]$zipfilename)
        set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
        (dir $zipfilename).IsReadOnly = $false
    }

    #get the zip file
    function Get-Zip
    {
        param([string]$zipfilename)
        if(test-path($zipfilename))
        {
            $shellApplication = new-object -com shell.application
            $zipFullFilename = (get-childitem $zipfilename).FullName
            $shellApplication.NameSpace($zipFullFilename)
        }
    }

    Posted: Friday, June 12, 2009 4:31 PM by ekraus
    Filed under:

    Comments

    No Comments

    Anonymous comments are disabled
    Page view tracker