Validation item in Sharepoint

…this post was published on 2017 March 03.

How we can force users to fill a secondary line text if another column ( yes/no ) is checked as Yes

Suppose that , the Yes/No column with the name yesno, and as single line text column I created the column <<textcolumn>>

The formulat I propose is
=10*yesno+COUNTA(textcolumn)<>10


and the result is this one

 

Posted in CalculatedColumn, Sharepoint, Sharepoint Online, Validation | Comments Off on Validation item in Sharepoint

Upload local folder structure with files on Sharepoint Online

…this post was published on 2017 February 12.

IF you would like to upload a complete structure of folders and subfolders on Sharepoint Online you can do it using Powershell and CSOM, using the following script.

You need to know the
– the URL of the site-collection ( looks like: https://tenant.sharepoint.com )
– the relative path of the destination site ( looks like: /sites/subsite_name )
– the library’s name where the files will be uploaded

Attention to the subfolders structure to not exceed the maximum URL length permited in Sharepoint Online

<#
DESCRIPTION
This script can be useful to update a specific field on a library located on a Sharepoint Online tenant
You need to know 5 mandatory parameters:
– url_sharepoint         : the URL for root site collection
– library                : the name of the destination library
– url_site               : the relative path of the site
Continue reading

Posted in Files, Powershell, Sharepoint Online, upload | Comments Off on Upload local folder structure with files on Sharepoint Online

Restoring multiple files versions in Sharepoint Online using Powershell

…this post was published on 2017 January 28.

Starting from this post, I attached a zipped document with the scripts needed to do the request.
The .zip file contains the files:
Online_RestoringFiles.ps1   – this is the main file which will use the second
Online_RestoringFiles_Functions.ps1 – the file with function needed in the main file

The script, need 3 mandatory params:
– the site’s URL  ( $Url )
– the library name ( $Library )
– the local folder ( $Download_Folder ) where the selected versions will be downloaded  before uploading them to the cloud )

Step1
After filling Online Credentials, the script will conect to the tenant, and will show all files in all folders and subloders.

Step2
The user need to select the filtering options, and the script will show these filtered files

Step3
For these filtered files, the versions will appear on screen, the user need to select which version will use to recover the file(s)

Step4
For each one, the file will be downloaded locally, and the user will can open and see the document

Step5
After locally download, the user will be asked to start the upload process to the cloud or stop it without upload

Step6
Final step, deleting the local created folder $Download_Folder

The zipped file can be downloaded here

Posted in Powershell, Sharepoint Online | Comments Off on Restoring multiple files versions in Sharepoint Online using Powershell

Download all images from all picture libraries on Sharepoint Online

…this post was published on 2017 January 19.

You can use following script. Save it  on your PC or run it directly using .ISE.
All Images will be saved in specific picture library​.

You need to download locally 2 libraries , if on your machine you don’t have SP on-premises installed. These 2 libraries are
Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Runtime.dll
To run the script, you need to know the site’s URL and credentials to access the site.

<#
DESCRIPTION
This script Will permit to downlaod locally all pictures from al Picture libraries in Sharepoint Online site
You need to know 1 mandatory parameters:
    – URL         : the URL for the site
Based on thus URL, it will create in current directory a new directoryy, and there for each Picture library a sub-folder with pictures
CopyRight
This script can be use as it is or can be changed based on your needs. For more details please feel free and contact me
Romeo Donca, January 2017
romeodonca@outlook.com
http://www.romeodonca.ro
#>
 
param(
[Parameter(Mandatory=$true,HelpMessage=”The url for the tenant where the picture library is, like https://TENANT-public.sharepoint.com”)][string]$Url
)  Continue reading
Posted in Powershell, Sharepoint Online | Comments Off on Download all images from all picture libraries on Sharepoint Online

Download specified doc version from Sharepoint 2010 library

…this post was published on 2017 January 17.

using Powershell, could be a challenge.

Why?
First you need to use version 2 , and if you already have other greater version installed on the machine you are forced to use only the console ( not the ISE env ) with param -version 2
Second, because is version 2 , you don have the cmdlet Invoke)WEbRequest to download file from specified address
In this case, on option is to use .NET , and define an object from class System.Net.WebClient.
$webclient = New-Object System.Net.WebClient
And because, connection need a user and password, you need to create a credential and attach it to that object
$cred = Get-Credential
$webclient.Credentials = $cred
To download  a file, you will use the method .DownloadFile, like this
$webclient.DownloadFile($sourcepath,$filename)
In my example I will check if the size of the version is greater than a specified value
The entire script to download the needed doc versions, is bellow, where you need to specify your values for
$siteurl =  Sharepoint 2010 site path
$library = The name of the library where docs are stored
$version =  which version of doc you want to check
$filesize = the minimum size in KB for the file
$pathfile = the location where the script will download the docs
 ​################### modify these params as necessary
$siteurl = ‘http://sp2010’
$library=”Library1″
$version = 1
$filesize= 17
$pathfile = “C:\Users\Administrator\Desktop\”
#######################
$cred = Get-Credential
$webclient = New-Object System.Net.WebClient
$site = get-spweb $siteurl
$mylist = $site.Lists[$library]
$items = $mylist.Items
foreach ( $item in $items)
    {
    if (($item.Versions.count -ge $version) -and ( ($item.Versions | where {$_.VersionLabel -eq $version.ToString()+’.0′})[‘File Size’] / 1KB -gt $filesize))
        {
        $sourcepath=$siteurl+’/_vti_history/’+$version*512+’/’+$library+’/’+$item.File.Name
        if($item.Versions.count -eq $version)
            {
            $sourcepath=$siteurl+’/’+$library+’/’+$item.File.Name
            }
        $filename=$pathfile+$item.name
        $webclient.Credentials = $cred
        $webclient.DownloadFile($sourcepath,$filename)
        $item.File.Name
        }
    }
Posted in Powershell, Sharepoint 2010 | Comments Off on Download specified doc version from Sharepoint 2010 library

Powershell DSC and Sharepoint standalone installation

…this post was published on 2017 January 11.

Let’s take the next step, to install Sharepoint on the target machine.
First, one remark. What about GUI versus command line setup process?
If you preffer the <<click>> method, you will click clik, for couple of times to install the ​​product and to fill the key as well.

But you have an extra option, to install by command line the setup.exe. This can be done like this
> setup.exe /config config.xml

This xml file is a pre-defined file for multple scenarios, and these files can be found using /files folder,in sharepoint setup kit. There you will see multpile folders, each one with his config.xml file

For standalone server, which is for this topic, the folder is /setupsilent, and the .xml ​file looks like

<Configuration>
 <Package Id=”sts”>
  <Setting Id=”LAUNCHEDFROMSETUPSTS” Value=”Yes”/>
 </Package>
 <Package Id=”spswfe”>
  <Setting Id=”SETUPCALLED” Value=”1″/>
 </Package>
 <Logging Type=”verbose” Path=”%temp%” Template=”SharePoint Server Setup(*).log”/>
 <!–<PIDKEY Value=”Enter Product Key Here” />–>
 <Display Level=”none” CompletionNotice=”no” />
 <Setting Id=”SERVERROLE” Value=”SINGLESERVER”/>
 <Setting Id=”USINGUIINSTALLMODE” Value=”0″/>
 <Setting Id=”SETUP_REBOOT” Value=”Never” />
 <Setting Id=”SETUPTYPE” Value=”CLEAN_INSTALL”/>
</Configuration>
where PIDKEY should be replaced by you with your own Sharepoint key; you should remove the comment <!– –> as well
Starting from the post, and I suppose that you already prepared the server with prerequisites, you could use the following script to prepare automatically the config.xml file and to install Sharepoint as Standalone on your target machine​.
The method, the third one ( after click,click and command line methods ) is using Powershell DSC
For this at the bottom of the article you will find 2 poershell scripts, zipped, which will execute the process with no action from you.
To use it, download the zip file and unzip it. This archive contains 2 file:
 i  – DSC_SP2013StandaloneMain.ps1
 ii – DSC_SP2013Standalone.ps1
The second one, DSC_SP2013Standalone.ps1  create the mof file needed to install Sharepoint. Few words about Package
       Package Sharepoint2013
            {
            Name = “Microsoft Sharepoint 2013”
            ProductID = ‘90150000-1014-0000-1000-0000000FF1CE’
            pATH=(join-Path $SharePoint2013Path ‘\setup.exe’)
            arguments=’/config config.xml’
            }
   Based on your Sharepoint installation kit, the Name and the ProductID could be different. To get the correct information, use regedit and browse for KEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall and there search for Sharepoint
More details about product ID , check this document​

 If the Product ID doesn’t match, you will receive at the end this error message, but the Sharepoint will be installed

$SharePoint2013Path variable is prepared in DSC_SP2013StandaloneMain.ps1 file, and represent the path for  the setup exe file . It will use the argument –   config.xml file, prepared in same  DSC_SP2013StandaloneMain.ps1 file.

The DSC_SP2013StandaloneMain.ps1 file will:
 – request the name for the target machine where Sharepoint 2013 will be installed;
 – prepare the shared folder  ( locally ) where Sharepoint 2013 kit will be copied with specific xml file , and you need to provide the folder name ( similar as in Prerequisites installation process );
 – will ask you for the SHarepoint kit location;
 – prepare config.xml, requesting the license key;
 – run DSC_SP2013Standalone.ps1 to prepare .mof files
 – set LCM on the target machine;
 – start the installation program , which it doesn’t need target machine to reboot;
 I recommend you to unzip the file ( at the bottom of this article ) in already existing working Powershell folder – c:\powershellscripts, and to run DSC_SP2013StandaloneMain.ps1
You can download the scripts here
ERRATA! ( until the next updates will come )
On line 38,39 please
replace sp2013 by your Domain name
replace “administrator” by a domain admin to permit rw to the shared folder

     New-SmbShare $folder_prerequisites -Path “c:\$folder_prerequisites” -ReadAccess “sp2013\$finalserver$” -Description “Sharepoint 2013 resources” -ErrorAction SilentlyContinue
    Grant-SmbShareAccess -Name $folder_prerequisites -AccountName “sp2013\administrator” -AccessRight Full  -Force
Posted in DSC, Powershell, Sharepoint 2013 | Comments Off on Powershell DSC and Sharepoint standalone installation

Update Sharepoint Online library document using Powershell

…this post was published on 2017 January 10.

if you need to update a Sharepoint online library d​ocument, or picture, you can use the following script.
The file, zipped can be found at the bottom , with the link to a video presentation of the script

<#
DESCRIPTION
This script can be useful to update a specific field on a library located on a Sharepoint Online tenant
You need to know 5 mandatory parameters:
    – URL         : the URL for the tenant
    – Library     : the name of the library where you need to update a doc/picture
    – ID          : the ID for that doc
    – Field       : the name for the field
    – NewValue    : the new value. If necessary change the type from [int] to [string]
CopyRight
This script can be use as it is or can be changed based on your needs. For more details please feel free and contact me
Romeo Donca, January 2017
romeodonca@outlook.com
http://www.romeodonca.ro
#>
param(
[Parameter(Mandatory=$true,HelpMessage=”The url for the tenant where the picture library is, like https://TENANT-public.sharepoint.com”)][string]$Url,
[Parameter(Mandatory=$true,HelpMessage=”The name for the library”)][string]$Library,
[Parameter(Mandatory=$true,HelpMessage=”The ID for the picture in that library”)][int]$ID,
[Parameter(Mandatory=$true,HelpMessage=”The field name that you want to be changed”)][string]$Field,
[Parameter(Mandatory=$true,HelpMessage=”The new value for that field”)][int]$NewValue
)
cls
Add-Type -Path “E:\DLLs\Microsoft.SharePoint.Client.dll”
Add-Type -Path “E:\DLLS\Microsoft.SharePoint.Client.Runtime.dll”
Import-Module MSOnline
$global:cred = Get-Credential
Connect-MsolService -Credential $global:cred -ErrorAction SilentlyContinue
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($cred.username, $cred.Password) 
$clientContext.Credentials = $cred
$web = $clientContext.Web
$clientContext.Load($web)
$clientContext.ExecuteQuery()
$mylist = $web.GetList($url+”/”+$library)
$clientContext.Load($mylist)
$clientContext.ExecuteQuery()
 
$caml=”<View><Query><Where><Geq><FieldRef Name=’ID’/><Value Type=’Number’>$ID</Value></Eq></Where></Query></View>”
$cquery = New-Object Microsoft.SharePoint.Client.CamlQuery
$cquery.ViewXml=$caml   
$listItemsinFlickr = $mylist.GetItems($cquery)
$clientContext.Load($listItemsinFlickr)
$clientContext.ExecuteQuery()

$continue = Read-Host ” You really want to modify fields for  picture ”  $listItemsinFlickr.FieldValues.Title ” ? (Y/N)”
while (!(($continue.ToUpper() -match ‘Y’) -or ($continuare.ToUpper() -match ‘N’)))
    {
    $continue = Read-Host ” You really want to modify fields for picture ”  $listItemsinFlickr.FieldValues.Title ” ? (Y/N)”
    }
switch ($continue.ToUpper())
{
    ‘Y’ {
            foreach ($item in $listItemsinFlickr)
                {
                $item[$field]=$newValue
                $item.Update()
                $clientContext.ExecuteQuery()
                cls
                write-host “The picture was been updated!”
                }
        }
    ‘N’ {
        cls
        write-host “Nothing has been changed!”
        }
}

You can download the script here

Posted in Powershell, Sharepoint Online | Comments Off on Update Sharepoint Online library document using Powershell

Powershell DSC to install Sharepoint 2013 Prerequisites in Windows 2008 R2 Server

…this post was published on 2017 January 9.

If you would like to install with zero ​touch on a target machine with 2012 R2 OS the prerequisites for Sharepoint server you can do it

First of all you need to setup  the target machine :
1. set the execution-policy to permit unsigned script to run
2. configure the group policy to permit .exe files to run without intervention
            User Configuration/Administrative Templates/Attachment Manager/Inclusion List for Low file types
                         ( Edit/Enabled/Specify low risk: .exe / Apply )

On the main server, the push server​
1. create a folder in which you’ll download the .zip file ( link )

This file contain following files:
i. –   DownloadSP2013PreReqFiles.ps1 – this file will download from the Internet needed prerequisites files, except 2 of them
ii. –  KB2671763.exe
   iii. – and WcfDataServices56.exe
   iv. – DSC_SP2013Prerequisitesmain.ps1 – the main script
v. –  DSC_SP2013W2012Prerequisites.ps1 –  this file will create .mof files needed for DSC to configure LCM on target machine and to install features and packages as well , when the target machine is a Windows 2012 R2 Server
vi – DSC_SP2013W2008R2Prerequisites.ps1 – for the windows Server 2008 R2

2. Unzip the zip file on the main/push server

3. Run DSC_SP2013Prerequisitesmain.ps1 file.

This script will:

– create and configure locally a folder where all needed resources for the process will be stored ( you need to provide a name for prerequisites packages , but you can keep the default value c:\sp2013_prerequisites, if you push Enter )
you need to provide the target’s name server
– download from the net the needed files to that folder and will copy files ( ii and iii )
– will chek the operating system on the target machine and will select the specific file which will create mof files ( in our scenario, the target machine is with 2008R2 OS, and so the file it is: DSC_SP2013W2008R2Prerequisites.ps1
– finally will start the DSC process, will push the config to the target LCM

​​The target machine will reboot 3 times after it is ready to support SP2013 software setup process

ERRATA! ( until the next updates will come )

On line 38,39 please
replace sp2013 by your Domain name
replace “administrator” by a domain admin to permit rw to the shared folder

 

    New-SmbShare $folder_prerequisites -Path “c:\$folder_prerequisites” -ReadAccess “sp2013\$finalserver$” -Description “Sharepoint 2013 resources” -ErrorAction SilentlyContinue
    Grant-SmbShareAccess -Name $folder_prerequisites -AccountName “sp2013\administrator” -AccessRight Full  -Force

Posted in DSC, Powershell | Comments Off on Powershell DSC to install Sharepoint 2013 Prerequisites in Windows 2008 R2 Server

.NET Framework 4.6 and Sharepoint installation

…this post was published on 2017 January 1.

Sharepoint it sn’t compatible with .NET Framework 4.6. To install it, you should first

1. remove update KB3102467
and
2.  block the installation later

For​ this , you can manually create a new entry in registry, or you can use the following Powershell script

Set-Location ‘HKLM:\Software\Microsoft\NET Framework Setup\NDP’
if (Test-Path WU)
{
     “Over-write the item”
     New-ItemProperty -Path .\WU -Name BlockNetFramework461 -Value 1 -PropertyType DWORD
}

else
{
    “Create the path and the key”
    New-Item -Path .\WU
    New-ItemProperty -Path .\WU -Name BlockNetFramework461 -Value 1 -PropertyType DWORD
}
Posted in .NET, Powershell | Comments Off on .NET Framework 4.6 and Sharepoint installation

Powershell DSC and Sharepoint farm installation


…this post was published on 2016 December 28.

Starting from this post, I will try to fill the table bellow, with <<Step by Step>> about DSC and Sharepoint 2013 or 2016 on different Windows OSs

​​​ ​​ Sharepoint 2013​​ ​​Sharepoint 2016
2008​ 2008 R2​ 2012 ​ 2012 R2​ 2016​ 200​​​8​ 200​​​8 R2​ 2012​ 2012 R2​​ ​​2016
​Special Steps ​N/A​ Yes​*2
​​
N/A​​ Yes​*1 X​ X​ X​ N/A​​ N/A​​​ ​​N/A​​
​Prerequ​isites ​N/A​ link​​ N/A​​ link X​ X​ X​ N/A​​ N/A​​​ ​​N/A​​
​Setup N/A​​ link​​​ N/A​​ link X​ X​ X N/A​​ N/A​ ​​N/A​​
​… ​N/A​​ N/A​ N/A​​ N/A​​ X​ X​ X N/A​ N/A​ ​​N/A​​​​
​… ​N/A​​ N/A​​ N/A​​ N/A​​ X​ X​ X​ N/A​ N/A​​​ ​​N/A​​

 

*1 check  more details on Sharepoint Prerequisites 2013​ on Windows Server 2012 R2
*2
check  more details on Sharepoint Prerequisites 2013​ on​ Windows Server 2008 R2

Details about .NET Framework 4.6 and SharePoint installation

Posted in .NET, DSC, Powershell | Comments Off on Powershell DSC and Sharepoint farm installation