Friday, 24 April 2020

CI CD with GitLab (.gitlab-ci.yml)

stages:
    - Build_and_Deploy

Build_and_Deploy:
  stage: Build_and_Deploy
  image: node:10.18.0
  only:
    - master
  tags:
    - gitlab-org
  script:
    - echo CI Started
    - npm i -g gulp
    - npm install -g @pnp/office365-cli
    - npm i
    - gulp bundle --ship
    - gulp package-solution --ship
    - o365 login -t password -u uname -p pswd

    - o365 spo app add -p ./sharepoint/solution/appname.sppkg --overwrite

    - o365 spo app deploy --name appname.sppkg --appCatalogUrl https://testaccount.sharepoint.com/sites/appcatalog/ --skipFeatureDeployment  
  allow_failure: false

Monday, 17 February 2020

SP Online - Handling external sharing using power shell



//Get all site collection
$SiteColl = Get-SPOSite  -Limit ALL

//Disable external sharing for all the site/site collection in the tenant
foreach($Site in $SiteColl)
{
    Write-host $Site.Url
    Set-SPOSite -Identity $Site.Url -SharingCapability Disabled
}


//Disable external sharing
Set-SPOSite -Identity "https://xxxx.sharepoint.com/sites/xxx" -SharingCapability Disabled

//To get Detailed list of sp site
Get-SPOSite -Identity "https://xxxx/sites/xxx" -detailed |fl

Wednesday, 27 March 2019

Delete list item using power shell with batch process

Start-Transcript -path C:\output.txt -append
$SiteUrl ="Site url"
$list =  (Get-Spweb "$SiteUrl").GetList("$SiteUrl"+/Lists/ListTitle/)
$query = New-Object Microsoft.SharePoint.SPQuery;
$query.ViewAttributes = "Scope='Recursive'";
$query.RowLimit = 2000;
$query.Query = '<Where><Leq><FieldRef Name="Created"/><Value Type="DateTime" IncludeTimeValue="TRUE">YYYY-MM-DDT00:00:00Z</Value></Leq></Where>';
#$query.Query = '';

$itemCount = 0;
$listId = $list.ID;
[System.Text.StringBuilder]$batchXml = New-Object "System.Text.StringBuilder";
$batchXml.Append("<?xml version=`"1.0`" encoding=`"UTF-8`"?><Batch>");
$command = [System.String]::Format( "<Method><SetList>{0}</SetList><SetVar Name=`"ID`">{1}</SetVar><SetVar Name=`"Cmd`">Delete</SetVar></Method>", $listId, "{0}" );
Write-Host "before do while "
Get-Date
do
{
    $listItems = $list.GetItems($query)
    $query.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
    foreach ($item in $listItems)
    {
        if($item -ne $null){$batchXml.Append([System.String]::Format($command, $item.ID.ToString())) | Out-Null;$itemCount++; write-host "Created on " $item["Created"] $itemCount }
    }
}
while ($query.ListItemCollectionPosition -ne $null)

$batchXml.Append("</Batch>");
$itemCount;
Write-Host "after do while "
Get-Date


#And lastly (and most importantly!), run the query
#Write-Host "Batch process started "
#Get-Date
#$web = Get-Spweb $SiteUrl;
#$web.ProcessBatchData($batchXml.ToString()) | Out-Null;
#Write-Host "Batch process end"
#Get-Date

Stop-Transcript