none
I am complete newbie and the first script I need to run has got me confused!! exporting best bets to csv

    Question

  • Hi all,

    This is my first time of using PowerShell and I have to run a script to export the best bets from our SharePoint search to a csv.  I have got the following script but don't know what I need to change to get it to work.  I am really exited about PowerShell but think I should have started a lot smaller.  Please help.

    #  ESP - Export keyword tool from SP-2010 --> CSV files 
    # 
    #  This tool will export SP-2010 keywords|bestbets|synonyms into CSV files 
    #  which you can later use with "import_CSV_FS4SP.ps1" script to import into FS4SP 
    #  configuration.  
    #  contributors: ceaykan, dabenson, brentgr  
    #  version: 1.02 
    # 
     
    cls 
     
    $global:configFile = "" 
    $global:siteid="" 
    $global:keywordsfile="" 
    $global:bestbetsfile="" 
    $global:synonymsfile="" 
    $global:proceed = $False 
    $global:help = "`n`n Definition : `n`n This tool is used for exporting keywords/bestbets/synonyms "+ 
                  "into CSV files `n from a Sharepoint 2010. The output of these files can be used as "+ 
                  "input for `n import_CSV_FS4SP.ps1 to import into a FS4SP setup. `n`n Example:"+ 
                  " .\export_SP2010_keywords_to_CSV.ps1 -c .\configuration.xml`n`n" ;  
                
    Add-PSSnapin Microsoft.Sharepoint.Powershell -ea SilentlyContinue 
     
    function checkFile($path) 
    { 
      $status = Test-Path $path 
         
      return $status 
    } 
     
    function ProcessConfigFile($configFile) 
    { 
      write-host ("[STATUS] Processing config file : " + $configFile) -ForegroundColor green 
           
      $doc = New-Object System.Xml.XmlDocument  
      $doc.Load($configFile)  
     
      $global:siteid = $doc.config.export_SP2010_CSV.SPsiteURL 
      $global:keywordsfile = $doc.config.export_SP2010_CSV.output_keywordsfile 
      $global:bestbetsfile = $doc.config.export_SP2010_CSV.output_bestbetsfile 
      $global:synonymsfile = $doc.config.export_SP2010_CSV.output_synonymsfile   
       
      write-host ("[STATUS] Using these configurations: `n") -ForegroundColor green 
      write-host ("`t site url to export from : " + $siteid) -ForegroundColor green   
      if(checkFile($keywordsfile))   
      {  
        write-host ("`t File allready exists, will overwrite : " + $keywordsfile) -ForegroundColor green ;  
        del $keywordsfile  
      }   
      else  
      {  
        write-host ("`t keywordsfile : " + $keywordsfile) -ForegroundColor green  
      } 
      if(checkFile($bestbetsfile))   
      {  
        write-host ("`t File allready exists, will overwrite : " + $bestbetsfile) -ForegroundColor green ;  
        del $bestbetsfile  
      }   
      else  
      {  
        write-host ("`t bestbetsfile : " + $bestbetsfile) -ForegroundColor green  
      } 
      if(checkFile($synonymsfile))   
      {  
        write-host ("`t File allready exists, will overwrite : " + $synonymsfile) -ForegroundColor green ;  
        del $synonymsfile 
      }   
      else  
      {  
        write-host ("`t synonymsfile : " + $synonymsfile) -ForegroundColor green  
      } 
       
      $temp = New-item -itemtype file $keywordsfile  -force 
      $temp = New-item -itemtype file $bestbetsfile  -force 
      $temp = New-item -itemtype file $synonymsfile  -force 
    } 
     
     
    write-host ("---------`n ESP - Export keyword tool from SP-2010 --> CSV files v.0.1 ") -ForegroundColor yellow 
    write-host ("`n This tool exports SP 2010 `n keywords/bestbets/synonyms into CSV files.`n-----`n") -ForegroundColor yellow 
     
     
    if (!$args) 
    { 
      write-host ("You must specificy command line arguments") -ForegroundColor red 
      write-host ("Try : -? for more info") -ForegroundColor red 
    } 
    else 
    {   
       
       
      switch($args) 
      { 
        "-c" {  
           if ($args[1] -ne $null) 
           { 
                
             write-host ("[STATUS] Will use config file : " + $args[1] +"") -ForegroundColor green 
             $global:configFile = $pwd.path + $args[1] 
                 
             if (checkFile($global:configFile))  
             {  
               ProcessConfigFile($global:configFile)  
               $global:proceed = $True 
             } 
             else  
             {  
               write-host ("[Error ] Config file " + $configFile + " does not exist!`n`n") -ForegroundColor red ;  
               $global:proceed = $False 
             }                         
           } 
           else  
           {            
             write-host ("[Error ] Need to specify the config file...!") -ForegroundColor red ;  
             $global:proceed = "False" 
           } 
         }     
        "-?" { write-host $global:help ; exit } 
      }   
       
      if ($global:proceed -eq "True") 
      { 
        $keywords = Get-SPEnterpriseSearchQueryKeyword -Site $global:siteid 
         
        #Add first line descriptors in all output files 
        "SpecialTerm" > $global:keywordsfile 
        "SpecialTerm, Synonyms" > $global:synonymsfile 
        "SpecialTerm, Title, URL, Description" > $global:bestbetsfile 
         
        foreach($keyword in $keywords) 
        { 
          $keyword.Term >> $global:keywordsfile 
               
          $tmpsynonym = $keyword.synonyms | select term 
          ($keyword.Term + "," + $tmpsynonym.term) >> $global:synonymsfile 
                         
          #Some keywords can be associated with multiple bestbets 
          if ($keyword.bestbets.count -eq 1) 
          { 
            $bestbetsTitle = $keyword.bestbets | select title 
            $bestbetsURL = $keyword.bestbets | select url 
            $bestbetsDescription = $keyword.bestbets | select description 
                   
            ($keyword.Term + "," + $bestbetsTitle.title + "," + $bestbetsURL.url + "," + $bestbetsDescription.description) >> $global:bestbetsfile 
          } 
          else 
          { 
            foreach($bet in $keyword.bestbets) 
            { 
              $bestbetsTitle = $bet | select title 
              $bestbetsURL = $bet | select url 
              $bestbetsDescription = $bet | select description 
                     
              ($keyword.Term + "," + $bestbetsTitle.title + "," + $bestbetsURL.url + "," + $bestbetsDescription.description) >> $global:bestbetsfile 
            } 
          }     
        } 
         
        write-host ("`n[STATUS] keywordsfile output captured ") -ForegroundColor green 
        write-host ("[STATUS] synonyms output captured ") -ForegroundColor green 
        write-host ("[STATUS] keywordsfile output captured ") -ForegroundColor green 
        write-host ("[STATUS] Job complete! `n`n") -ForegroundColor green 
      } 
      else 
      { 
        $global:help 
      } 
    }

    

    Thank

    Barry


    • Edited by BarryLong Friday, March 08, 2013 11:10 AM
    Friday, March 08, 2013 10:14 AM

Answers

  • OK so you have the config file.  What you need to do now id=s specify it on the command line when you execute the script.

    example:  powershell .\export_SP2010_keywords_to_CSV.ps1 -c .\configuration.xml

    In this example the file is specified by the option -c and the path to the file is .\configuration.xml

    to see the help display run this from the command line

    powershell .\export_SP2010_keywords_to_CSV.ps1 -?

    That is what the error tells you.

    Friday, March 08, 2013 7:06 PM

All replies

  • I have now updated and put the script in.
    Friday, March 08, 2013 11:20 AM
  • You have failed to state your problem other that to say how confused you are and that you have been exited from PowerShell?

    You must tell us what errors you are getting. 

    You should ask the creators of this script for help.


    ¯\_(ツ)_/¯

    Friday, March 08, 2013 11:44 AM
  • This is a script from the microsoft site.

    I keep getting the following:

    ---------
     ESP - Export keyword tool from SP-2010 --> CSV files v.0.1 
     This tool exports SP 2010 
     keywords/bestbets/synonyms into CSV files.
    -----
    You must specificy command line arguments
    Try : -? for more info

    Friday, March 08, 2013 11:48 AM
  • It is asking you to enter the path\name of the config file that it is supposed to use as input.  See these lines from the help section.

    $global:help = "`n`n Definition : `n`n This tool is used for exporting keywords/bestbets/synonyms "+
                 
    "into CSV files `n from a Sharepoint 2010. The output of these files can be used as "+
                 
    "input for `n import_CSV_FS4SP.ps1 to import into a FS4SP setup. `n`n Example:"+
                 
    " .\export_SP2010_keywords_to_CSV.ps1 -c .\configuration.xml`n`n" ; 

    How that config file is structured you will have to ask the author of the script.


    Friday, March 08, 2013 2:28 PM
  • the config file looks like this I have tried to modify this, not sure I got it right.

    <config>
      <export_SP2010_CSV>
       <!-- The Microsoft Search Server 2010 site to export keywords/bestbets/synonyms into CSV files -->
       <SPsiteURL>http://search/Pages/</SPsiteURL>  
       <!-- The path+filenames for the output CSV files -->
       <output_keywordsfile>.\csv\keyword.csv</output_keywordsfile>
       <output_bestbetsfile>.\csv\bestbet.csv</output_bestbetsfile>
       <output_synonymsfile>.\csv\synonym.csv</output_synonymsfile>
      </export_SP2010_CSV>
     
    </config>

    Friday, March 08, 2013 3:36 PM
  • OK so you have the config file.  What you need to do now id=s specify it on the command line when you execute the script.

    example:  powershell .\export_SP2010_keywords_to_CSV.ps1 -c .\configuration.xml

    In this example the file is specified by the option -c and the path to the file is .\configuration.xml

    to see the help display run this from the command line

    powershell .\export_SP2010_keywords_to_CSV.ps1 -?

    That is what the error tells you.

    Friday, March 08, 2013 7:06 PM