Posts tonen met het label Sharepoint 2010. Alle posts tonen
Posts tonen met het label Sharepoint 2010. Alle posts tonen

maandag 11 maart 2013

Export Termset and Terms





Here is a script to export the termsets and terms from SharePoint.

I found this script on this site on internet.


function Export-SPTermSet {
  param (
  [Microsoft.SharePoint.Taxonomy.TermCollection]$terms,
  [int]$level = 1,
  [string]$previousTerms = ""
)

if ($level -ge 1 -or $level -le 7) 
{
   if ($terms.Count -gt 0 ) 
   {
      $termSetName = ""
      if ($level -eq 1) 
      {
         $termSetName =  """" + $terms[0].TermSet.Name.Replace([System.Text.Encoding]::UTF8.GetString($amp), "&") + """"
      }
      $terms | ForEach-Object {
      $currentTerms = $previousTerms + ",""" + $_.Name.Replace([System.Text.Encoding]::UTF8.GetString($amp), "&") + """";

      $file.Writeline($termSetName + ",""" + $_.TermSet.Description + """" + ",," + $_.IsAvailableForTagging +"," + $_.GetDescription() + $currentTerms);

      if ($level -lt 7) 
      {
         Export-SPTermSet $_.Terms ($level + 1) ($previousTerms + $currentTerms)
      }
   }
}
}
}


function Export-SPTerms {
param (
[string]$siteUrl = $(Read-Host -prompt "Please provide the site collection URL"),
[string]$termGroupName = $(Read-Host -prompt "Please provide the term group name to export"),
[string]$saveLocation = $(Read-Host -prompt "Please provide the path of the folder to save the CSV file to")
)

if ([IO.Directory]::Exists($saveLocation) -eq $false)
{
New-Item ($saveLocation) -Type Directory | Out-Null
}

$taxonomySession = Get-SPTaxonomySession -site $siteUrl
$taxonomyTermStore =  $taxonomySession.TermStores | Select Name
$termStore = $taxonomySession.TermStores[$taxonomyTermStore.Name]

# Ampersands are stored as fullwidth ampersands (see http://www.fileformat.info/info/unicode/char/ff06/index.htm)
[Byte[]] $amp = 0xEF,0xBC,0x86

foreach ($group in $termStore.Groups) {
if ($group.Name -eq $termGroupName) {
foreach ($termSet in $group.TermSets) {
# Remove unsafe file system characters from filename
$parsedFilename =  [regex]::replace($termSet.Name, "[^a-zA-Z0-9\\-]", "_")
$file = New-Object System.IO.StreamWriter($saveLocation + "\termset_" + $parsedFilename + ".csv")

# Write out the headers
$file.Writeline("Term Set Name,Term Set Description,LCID,Available for Tagging,Term Description,Level 1 Term, Level 2 Term,Level 3 Term,Level 4 Term,Level 5 Term,Level 6 Term,Level 7 Term")

try {
Export-SPTermSet $termSet.Terms
}
finally {
$file.Flush()
$file.Close()
}
}
}
}
}

maandag 28 januari 2013

Get all recycle bins filled with content.







To know in which sitecollection the recycle bin is filled.

Function GetallFilledRecyclebins($LogFile, $SiteUrl)

{
     Start-Transcript -Path $LogFile


     $sitecollection = SPSite($SiteUrl)

     foreach ($web in $sitecollection.AllWebs)

     {
        
Write-Host $web.Url + "->" +  $web.RecycleBin.Count

     }

     Stop-Transcript

}

GetallFilledRecyclebins c:\temp\log.log http://www.url.com

Get all version enabled lists







To search on all site collections manually to version enabled lists takes a lot of time.

So because of that i wrote a ps script.

Function GetAllVersionEnabledLists($LogFile, $SiteUrl)
{

if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
Add-PSSnapin Microsoft.SharePoint.PowerShell;
}

Start-Transcript -Path $LogFile

$sitecollection = SPSite($SiteUrl)
foreach ($web in $sitecollection.AllWebs)
{
foreach($list in $web.lists)
{
if ($list.EnableVersioning -eq $true)
{
Write-Host ($site.Url +"-" +  $web.Title +"-"+ $list.Title + "->" + $list.EnableVersioning)
}
}
}

Stop-Transcript
}


Example : GetAllVersionEnabledLists c:\temp\log.log http://url 

dinsdag 22 januari 2013

Read ULS log with powrshell


When solving issues on a SharePoint environment. You need a lot of times take a look at the ULS logs of SharePoint. Instead of logging in on a remote desktop connection (RDC) you can create a file share of the log files folder of SharePoint.

With the next PowerShell script you can read the uls logs via the file share based on your Correlation ID.



Function Get-ULSLog ($correlationid, $timelimit = 30) {
                @("Server 1","Server 2","Server 3") |
                % {gci "\\$_\Name of the file share\*.log"} |
                ? { $_.LastWriteTime -gt (Get-Date).AddMinutes(-$timelimit)} | 
                import-csv -delim "`t" | ? {$_.Correlation -match $correlationid}
}


Get-ULSLog "Correlation ID" 30



Have fun, it will save a lot of time.

vrijdag 2 december 2011

Powershell & SharePoint

Yesterday i received an interesting blog item from my colleage which i wanted to share with you.

Hi All,

If you are thinking about creating a SharePoint environment with the help of our friend PowerShell, you will discover that almost everything is possible.

So let's create a  'User' (person/group) column :

### Add custom site column ###

$fieldXML = ' Name="myUser"
Description="name it"
Type=”User”
DisplayName="Add me to your list ..."
Group="Custom Columns"
Required="true"
ShowInDisplayForm="true"
ShowInEditForm="true"
ShowInListSettings="true"
ShowInNewForm="true"
List="UserInfo"
ShowField="ImnName"
UserSelectionMode = "PeopleOnly"
UserSelectionScope = "0">
'
$spWeb.Fields.AddFieldAsXml($fieldXML)

$spWeb.Update()

The column will appear in the 'Custom Columns'


Next thing, we will add this column to a content type :

### Add column to CT ###

$spColumn = New-Object Microsoft.SharePoint.SPFieldLink ($spWeb.Fields["Name"])

$Ct = $spWeb.ContentTypes["ContentType"]

$Ct.FieldLinks.Add($spColumn)

$Ct.Update()

Your site column was added to your content type ...


Enjoy PowerShell :-)

maandag 9 augustus 2010