Living a SharePoint life

Showing posts with label Code Snippet. Show all posts
Showing posts with label Code Snippet. Show all posts

Friday, March 15, 2019

Setting SharePoint View properties with the PnP-Framework

The PnP-Framework has made a lot of task easier when taking care of a SharePoint environment. However, the documentation is still… ehem, let’s say developer friendly. In this article I’ll take a look at the Set-PnPView cmdlet and what values can be configured and why.


Wednesday, February 1, 2017

Code Snippet: Load the SharePoint Office PnP Module in PowerShell

How do you load the PowerShell OfficeP PnP module for SharePoint?

Addendum: I've added a try/catch block to the code. This way you can be sure the module is loaded.

# Loading Office Online PnP Module
try {
    if((Get-Module "Microsoft.Online.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
        Import-Module Microsoft.Online.SharePoint.PowerShell
        Write-Host "PowerShell module Microsoft.Online.SharePoint.PowerShell initialized"
    }
    else {
        Write-Host "PowerShell module Microsoft.Online.SharePoint.PowerShell loaded"
    }
}
catch {
    throw "PowerShell module Microsoft.Online.SharePoint.PowerShell initialization failed"
    exit 3
}

Tuesday, January 17, 2017

Connect to Office365 via Office PnP behind a proxy

How do you connect to your SharePoint Office365 tenant with the PowerShell if you are locked behind a proxy? This hint will probably work for all kind of PowerShell scripts, not only for Office PnP. I tried this with the Microsoft SharePoint Online extensions as well and it worked.

So my problem was, the company I was working for, had a proxy which could not be bypassed. The proxy settings have been set by a GPO and the network settings where fine so far. However the proxy used user authentication to access the internet. Now if I want to use the SharePoint Online tools, I must authenticate my PowerShell session at the proxy so the tools can access the internet too.

The trick to get your PowerShell connected is quite simple. You only need to enter the following line:

[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials

Now you should be able to connect to Office365 SharePoint without problems. If you don't want to enter this line every time you open a new PowerShell, you could add it to your PowerShell profile.

ise $PROFILE
then add this to the profile file:

#Set user default credentials for any webrequest
"Setting the users default credentials for WebRequests..." | Write-Host -ForegroundColor White
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials

Thursday, September 1, 2016

Useful links

Sometimes I stumble upon links in the net I find useful. I tend to save these links for the future because I 'might' use them in some project. I'd like to share these links with you and maybe you find them useful as well for a future project of yours.

Enable Enterprise Keywords column in a blank siteEnable Enterprise Keywords column in a blank site
Trouble to enable the Enterprise keywords column? This might be the cause.

The 2013 SPSFarmReport
Get a overview of your SharePoint Farm.

SharePoint Health Analyzer Rules
The SharePoint Health Analyzer Rules project is a collection of configurable SharePoint health analyzer rules that extends out of the box Health Analyzer system by adding many important additional rules that help to ensure your SharePoint environment is kept in optimal condition.

SharePoint Managed Metadata Navigator
Use SharePoint Managed Metadata Navigator to browse, explore, create, update, delete, export and import MMD Groups, Termsets, and Terms for SharePoint 2010.

http://spribbonvisibility.codeplex.com/
Choose who can see the SharePoint ribbon.

http://ribbonmanager.codeplex.com/
Hide different elements on a SharePoint page.

SharePoint Social Networking
A Collection of solutions aimed at adding social networking to your SharePoint 2010 site. The collection will include web parts, ribbon extensions and other type of solutions that will add or enhance the social networking capabilities of SharePoint.

SharePoint Document Converter
SharePoint Document Converter solution gives a start on how we can leverage the Word automation Service to convert documents to formats that word can support. This project convert documents of type "DOCX" or "DOC" to any possible file type that word support like to PDF, XPS, DOCX, DOCM, DOC, DOTX, DOTM, DOT, XML, RTF, MHT.

Wednesday, October 21, 2015

Change the SQL recovery model in bulk with the PowerShell

Sometimes you need to configure settings on your SQL server in bulk, like e.g. the recovery model. In my case, we needed to change all databases to the Full recovery model, due to the usage of Always-On. Scince SQL 2012 there is a great way to do this with the PowerShell.

First open a Powershell and see if the SQL PowerShell module is loaded.
Get-Module SQLPS
If it isn't loaded, do so by using
Import-Module SQLPS
For scripts you should check if the module is loaded before you import it like this:

if ((Get-Module "SQLPS" -ea silentlycontinue) -eq $null)
{
    Import-Module SQLPS -DisableNameChecking
}
Now you can change to the SQL server by simply entering SQLSERVER:

Use ls or dir to see what options you have

Change the 'directory' with cd SQL. This way you go to the SQL server configuration. Do so as well for the servers host name and the SQL server instance, until you you enter the databases directory. Here you'll find all the databases hosted by the SQl server instance you choose. Now we can run the following script to change the recovery model in bulk.
foreach ($db in ls) {
  if ($db.RecoveryModel -ne "Full") {
    $db.RecoveryModel = "Full"
    $db.Alter()
  }
}

Wednesday, April 1, 2015

Adding PDF and other MIME Types to the Browser File Handling property

PDF Icon
By default a WebApplication in SharePoint doesn’t consider PDF files safe. If you click on one you may download it to your computer, but can’t view it with Acrobat inline in your browser. Learn how to change this behavior.

Using PDF files in SharePoint is however a very common task. You can store them in document libraries like every other document, open and save them or move them around. But not being able to open the PDF inside of the browser is a very annoying behavior and it forces the user to save copies on their local computer. Haven’t we installed SharePoint to get rid of local copies swarming around the office?

Wednesday, February 18, 2015

SharePoint Tools: A new CAML Query Designer

Praveen Battula has released a new tool on his blog to work with CAML Queries. Not only you can export the plain CAML Query it self, the tool lets you generate code for C#, JavaScript, WebServices and PowerShell as well.

Have a look at his blog:
http://praveenbattula.blogspot.de/2015/02/download-caml-query-designer.html

Wednesday, January 21, 2015

Code Snippet: Iterating thru all websites

How to iterate thru all SiteCollections and containing the Websites. This script also shows a progressbar on screen:

$sites = Get-SPSite -Limit All
$siteIter = 0
foreach($site in $sites) {
    Write-Progress -PercentComplete (($siteIter / $sites.Count) * 100) -Activity "Iteration Sites" -Status $site.HostName
    $webIter = 0
    
    # Do something here
    
    foreach($web in $site.AllWebs) {
        Write-Progress -PercentComplete (($webIter / $site.AllWebs.Count) * 100) -Activity "Iteration Webs" -Status $web.Title -Id 2
        Write-Host $web.Title
        $webIter++
        
        # Do something here
    }
    $siteIter++
}

Code Snippet: Load the SharePoint PowerShell Module

How do you load the PowerShell module for SharePoint?

Addendum: I've added a try/catch block to the code. This way you can be sure the module is loaded.

# Loading SharePoint Module
try {
    if ((Get-PSSnapin "microsoft.SharePoint.Powershell" -ea silentlycontinue) -eq $null)
    {
        Add-PSSNapin Microsoft.SharePoint.Powershell
    }
}
catch {
    throw "Microsoft SharePoint PowerShell AddIn initialization failed"
    exit 3
}

Featured Post

How are Microsoft Search quota consumed?

With Office 365 Search, Microsoft has created a central entry point for the modern workplace. In one convenient spot, users can access all ...