Wednesday, December 5, 2018

SharePoint: Get all Site Collections, Lists, Libraries, Folders and Items

Back in 2015 I wrote a script to get all document libraries from all site collections of a web application. I went back to the script to update it a bit. The updates version gets all lists & libraries, searches for all folders and items and gives you a count of folders, items an the size of the site collection.

Wednesday, November 28, 2018

Azure Functions, FTP and PowerShell Modules

I already showed you how to get a PowerShell in an Azure Functions off the ground. How about we actually use it with some modules that are not included in Azure Functions? This post will explain how to get FTP going and upload a module and how to import that module into your script.

We start at the "Overview" of our Azure Function, it's the same one I created a couple of weeks ago for another post. It looks like this:

Click on "Platform features" and there select "Deployment Center":

This is also new in Azure Functions, it was updated along side the Azure Functions v2. But don't worry, FTP is still here! You might have to scroll on the next screen, because it's at the bottom of the list. At least in my case.

Click in "FTP" and then select "Dashboard" right below it.

You know have to two options: "App Credentials" or "User Credentials". With "User Credentials" you can create an Azure Functions FTP user, so you can have one FTP account for all your apps. Of course we don't do that. I'm using "App Credentials", because I rarely log into my App with FTPS.The credentials are automatically created and can be reset by a push of a button. You can also see the FTPS endpoint above the credentials.


But you can also check under "Platform features". Click on "Properties" to get a list of information you might need. In our case we only need the "FTP/Deployment User" and the "FTP Host Name":

Now we just connect via Windows Explorer to the FTPS Server. You will see a couple of messages to provide the user and the password.

If you succeeded, you will see a screen like this:

Because I was super smart when creating this test function, I decided not to give it a proper name but instead stick with the default name. The default name is "HTTPTriggerPowerShell1". Open that folder to see "run.ps1" and "function.json". We will place our module in here, somewhere.

You know what? We forgot to get our PowerShell modules! Welp, we have to do that now, I guess. Open your PowerShell window and enter this command: Save-Module msonline -Repository PSGallery -Path "C:\temp". I will store the "MSOnline" module that you have installed on your computer in "C:\temp\MSOnline\VERSIONNUMBER". Like this:

I have multiple version, because over time you have to update your modules in Azure Functions. So I'm collection them by now. Go back to the FTPS in your Windows Explorer and create a new folder called "bin". You can name it whatever you want, "bin" is just an example. I you give the folder a different name, you will have to change the script later on.

Upload the "MSOnline" folder, so it looks like this:

Finally we can import the module in our Azure Function:

And here's the script. You might have to change the folder name "bin", depending on your setting. Also after each change to the module "MSOnline", f. ex. using a newer version, you will have to change the version number in the script. In the example it's called "$MSOLVersion". Also: The function name! Never keep the default names, you will get crazy trying to fix issues. It's fine if you are just testing out a system, but please change the names with descriptive names!

Wednesday, November 21, 2018

SharePoint Migration with Sharegate and PowerShell

Sharegate is a really nice tool to migrate stuff across different SharePoint version, from on-premise 2007 to the newest cloud version. But with the UI you always have to create tasks for the migration. Why not use a CSV and PowerShell to make that happen?

First of all we need a CSV. I chose this design:

type;sourceurl;destinationurl;sourceList;destinationList;sourcefolder;destinationfolder;title

You have to provide a type, currently it could be "LIST", "FOLDER" and "UNC". You also need to provide destination and source and of course a title. The title will be use to create the file name for the log. A final CSV would look like this:

Link to the raw file
The script itself is a simple one. We import the Sharegate Module for PowerShell and load the MigrationList.csv. After that we check every entry of the CSV and load the item. The "type" defines which function will get used to migrate the content.

For LIST: Copy-Content -SourceList $srcList -DestinationList $destList -ExcelFilePath $fileName
For FOLDER: Copy-Content -SourceList $srcList -DestinationList $destList -SourceFolder $sourceFolder -DestinationFolder $destinationFolder -ExcelFilePath $fileName
For UNC: Import-Document -SourceFolder $sourceURL -DestinationList $destList -ExcelFilePath $fileName

Here's the script in its entirety: You can find the repository here: Github

Wednesday, November 14, 2018

Azure Functions with PowerShell

Azure Functions are really appealing for everything that has to do with automation. I use it for example to create new users in Office 365 or to lock files in SharePoint. I use Function Apps with HTTP Trigger and with a scheduler. In this post I will sho you how to get started with PowerShell in Azure Functions.

Your Azure Portal should like something like this (November 2018):


Select "Create a resource":


Search for "function app" and should see the "Function APP" as the first result:


Select the item and click on "Create":


Fill out the form. The App name must be unique, but Azure will give you hints if the name is taken.


Azure will create the App, which might take a couple of minutes. After creation you can search for your appname under "All resources":


Now here's the kicker: Microsoft introduced some changes in September 2018 when they deployed Azure Functions v2. They dropped the support for PowerShell and other "experimental languages", so you will NOT be able to find them in v2 Function Apps. But don't worry! We just set the function back to v1. select "Function app settings":


You can also click on the app and select "Platform features" and then "Function app settings":


Now simply click on "~1" to select Azure Functions v1:


To get an app off the ground, select "Functions" and "New function" or click on the "+" next to "Functions":


Select "create your own custom function":


You should see something like this. Notice that PowerShell is missing there:


To get to PowerShell toggle "Experimental Language Support" to "Enabled":


In this example I used a HTTP trigger Azure function. Select the language and change the name:


After clicking on create you are greeted with this screen:


Yes! We did it! Now we can use PowerShell in Azure Functions! You will have to keep the header, just start coding below the content that is already there and you are good to go.

Friday, October 12, 2018

Add User to User Policy

I wanted to add a specific admin-stlye account to the User Policies in SharePoint 2013 but didn't have access to the Central Administration. Here's the PowerShell solution I used:

In this case I wanted full control, which you can see here: [Microsoft.SharePoint.Administration.SPPolicyRoleType]::FullControl