Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

Monday, January 28, 2019

Powershell to replace string in infopath in SharePoint Document library

So here is a simple/dirty script to update the files in your document library.  this particular script is for infopath documents with the template pointing to the wrong url after a migration

Add-PSSnapin *sharepoint* -EA SilentlyContinue

$web = Get-SpWeb https://url

#find your list (your call on what method to use
$list = $web.Lists[0] 

$oldstring = "https://url/libraryname/Forms/template.xsn"

$newstring = "https://url/Newlibraryname/Forms/template.xsn"

foreach($i in $list.Items)
{
  if($i.Title.Contains('.xml'))
  {
     $data = [System.Text.Encoding]::ASCII.GetString($i.File.OpenBinary())
     if($data.Contains($oldstring)
     {
         $data = $data.Replace($oldstring, $newstring)
       
          $i.File.SaveBinary([System.Text.Encoding]::ASCII.GetBytes($data))
      }
  }

}

Tuesday, April 5, 2016

Powershell script to generate powershell script to toggle publish feature

Add-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$url = {your url here}
$site = get-spsite $url
$feature = $site.features.Item('f6924d36-2fa8-4f0b-b16d-06b7250180fa')
        
    if($feature -ne $null)
       {
            $ConfirmPreference = 'None'
       #     $feature
       #     Write-Host Disable-SPFeature -Identity $feature.DefinitionId -Url $site.Url -Force  -WarningAction SilentlyContinue
            Write-Host enable-SPFeature  -Identity $feature.DefinitionId -Url $site.Url  -Force   -WarningAction SilentlyContinue
      
       }
foreach($w in $site.AllWebs)
{
  #  Write-Host '#--------------------------------------------------------------------------------------'
  #  $w.Url
    $feature = $w.features.Item('94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb')
        
    if($feature -ne $null)
       {
       $ConfirmPreference = 'None'
         #   $feature
         #  Write-Host  Disable-SPFeature -Identity $feature.DefinitionId -Url $w.Url -Force  -WarningAction SilentlyContinue
            Write-Host enable-SPFeature  -Identity $feature.DefinitionId -Url $w.Url  -Force   -WarningAction SilentlyContinue
      
       }

}

Wednesday, January 14, 2015

SharePoint 2013 Hide upload and disable drag drop for document library

Add a script web part with the following:

<style type="text/css">
#Ribbon\.Documents\.New\.AddDocument-Large
{    
               display:none !important;
}
</style>
<style type="text/css">
td.ms-addnew
{    
               display:none !important;
}
</style>

<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(function() {
    g_uploadType = DragDropMode.NOTSUPPORTED;
    SPDragDropManager.DragDropMode = DragDropMode.NOTSUPPORTED;
}, "DragDrop.js");

</script>

Wednesday, August 14, 2013

PowerShell Script to mount and Upgrade all site collections in a web application

Sometimes, the visual upgrade gets a bit buggy so use this instead and have no issues. Make sure you export all the solutions from the old central admin and add them and deploy them to the new Sharepoint 2013 environment. This way you will not have issues with the webparts and pages.

Add-PSSnapin Microsoft.SharePoint.Powershell
Mount-SPContentDatabase CSIHQ_Content -WebApplication http://server.com -AssignNewDatabaseId -DatabaseServer Dbservername
$SPwebApp = Get-SPWebApplication "http://server.com"
foreach ($SPsite in $SPwebApp.Sites) { Upgrade-SPSite $SPsite.Url -VersionUPGrade write-host $SPsite.url }