Wednesday, November 15, 2017

How to create File Share on Azure

Hi, i am working with azure these days, and the first thing i did was to create my own file share on the cloud/accessible via instead of using one drive or google drive.
So here are very easy steps to create your own cloud based shared drive on the Azure:-





  1. Login to azure portal:- https://portal.azure.com
  2. Click New and next search the market place for storage account (Use if you have any existing one)
  3. Click Create and keep settings as shown in figure below, the most important thing among settings is performance, for file share the performance have to be standard as Files storage is not available in Premium performance

  4. Wait for it to be created, next once created open the storage account and click on overview, next click on the Files in the adjacent window to open file service and click + to add a new file share:-

    One thing to note here that we can have file share size upto 5 TB i.e 5120 GB only
  5. Next click ok and we are good. to access it just open the file storage and click on Connect. You can choose the connection guidelines as per your wish, i prefer using "new use" command. Just copy the new use command and run command shell on your machine and paste the copied string and hit enter.

    Basically the string you copied is "net use [File Share Path] [User Account] [Access Key1 of Storage Account]".
  6. Just to add here, lets see the cost of creating 1 TB File Share Per Month on Pricing Calculator:-
  7. 62 Dollars plus operations cost.

Tuesday, October 10, 2017

SharePoint Online, PowerShell and Rest API : Introduction


In this blog i will show you how to execute Rest API calls via PowerShell for SharePoint Online(Office 365 Tenant).

I am using SharePoint Online PnP MSI here.

You must have already heard about PowerShell MSI for SharePoint Online developed by Erwin van Hunen and included in SharePoint PnP, i will use the same for connecting to SharePoint online via Powershell, you can download the same using this url:-

https://github.com/SharePoint/PnP-PowerShell/releases

Note:- You will need to have Powershell 3.0 to use SharePoint Online msi of SharePoint PnP.

to View all Commands in PnP, type :-

Get-Command -Module *PnP*

Here is the URL for help documentation for commands:-

https://github.com/SharePoint/PnP-PowerShell/blob/master/Documentation/readme.md


Once you have installed it, lets see how to execute Rest API calls via Powershell.

You can use Windows Powershell ISE, SharePoint Online Management Shell, CMDER

I am using CMDER to demo this:-

Open CMDER and type Powershell, and then load modules:-

If you are using cmder first time and would like to work using it with PowerShell Online, then import the module like this:-












Now we are ready to write our Command to talk to Rest API.

Follow these simple steps:-

  1. Connect to SP Online:-

     
    $email = Read-Host -Prompt "Please enter your tenant account email"
    $pass = Read-host -AsSecureString "Please enter tenant admin password"
    $credentials = New-Object –TypeName "System.Management.Automation.PSCredential"
     –ArgumentList $email, $pass
    $targetSite = "https://.sharepoint.com/sites//"
    $targetSiteUri = [System.Uri]$targetSite
    Connect-PnPOnline $targetSiteUri -Credentials $credentials
    
    
    
  2. Next retrieve the context from the connection:-

     
     $context = (Get-PnPWeb).Context
    
  3. Grab related authentication cookies

     
    #this is different object then other credentials used earlier
    $spcredentials = $context.Credentials
    $authenticationCookies = $spcredentials.GetAuthenticationCookie($targetSiteUri,
    $true)
    
    
  4. Initiate a web session and set Cookies and accept headers to it

    $webSession = New-Object Microsoft.PowerShell.Commands.WebRequestSession
    $webSession.Cookies.SetCookies($targetSiteUri, $authenticationCookies)
    $webSession.Headers.Add("Accept", "application/json;odata=verbose")
    
    
  5. Rest call constructs, here we are just retrieving data of a library with a normal get request.

    $targetLibrary = "Documents"
    $apiUrl = "$targetSite" + "/_api/web/lists/getByTitle('$targetLibrary')"
    
  6. Invoke the request

    $webRequest = Invoke-WebRequest -Uri $apiUrl -Method Get -WebSession $webSession
    
  7. Get the results

    $jsonLibrary = $webRequest.Content | ConvertFrom-Json
    
This is how it will appear in the shell:-







we have successfully executed our Rest Call to SharePoint online.

To view the results you can consider d as an object and execute Select:-



Entire PS Script:-

$email = Read-Host -Prompt "Please enter your tenant account email"
$pass = Read-host -AsSecureString "Please enter tenant admin password"
$credentials = New-Object –TypeName "System.Management.Automation.PSCredential"
 –ArgumentList $email, $pass

$targetSite = "https://.sharepoint.com/sites//"
$targetSiteUri = [System.Uri]$targetSite
Connect-PnPOnline $targetSiteUri -Credentials $credentials
$context = (Get-PnPWeb).Context
#this is different object then other credentials used earlier
$spcredentials = $context.Credentials
$authenticationCookies = $spcredentials.GetAuthenticationCookie($targetSiteUri,
$true)

$webSession = New-Object Microsoft.PowerShell.Commands.WebRequestSession
$webSession.Cookies.SetCookies($targetSiteUri, $authenticationCookies)
$webSession.Headers.Add("Accept", "application/json;odata=verbose")
$targetLibrary = "Documents"
$apiUrl = "$targetSite" + "/_api/web/lists/getByTitle('$targetLibrary')"
$webRequest = Invoke-WebRequest -Uri $apiUrl -Method Get -WebSession $webSession
$jsonLibrary = $webRequest.Content | ConvertFrom-Json
$jsonLibrary.d | Select *