Showing posts with label Powershell. Show all posts
Showing posts with label Powershell. Show all posts

Thursday, March 18, 2021

How to list all sites and subsites in SharePoint Online using PowerShell?

function Get-SPOWebs(){

param(

   $Url = $(throw "Please provide a Site Collection Url"),

   $Credential = $(throw "Please provide a Credentials")

)


  $context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)  

  $context.Credentials = $Credential 

  $web = $context.Web

  $context.Load($web)

  $context.Load($web.Webs)

  $context.ExecuteQuery()

  foreach($web in $web.Webs)

  {

       Get-SPOWebs -Url $web.Url -Credential $Credential 

       $web

  }

}

Saturday, January 23, 2021

Last Modified date for site collection?

 Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Office.Server.Search.Query”)  


[String]$lastDate = "1/1/2018"


foreach($sc in $webapplication | Get-SPSite -Limit All)

{

    Write-Host $sc.Url -ForegroundColor Yellow


    $keywordQuery = New-Object Microsoft.Office.Server.Search.Query.KeywordQuery($sc)

    $keywordQuery.QueryText = "ContentClass:STS_ListItem AND LastModifiedTime>=$($lastDate) AND site:$($sc.Url)"

    $keywordQuery.RowLimit = 5;

    $searchExec = New-Object Microsoft.Office.Server.Search.Query.SearchExecutor

    $searchResults = $searchExec.ExecuteQuery($keywordQuery)


    If( 0 -eq $searchResults.Table.Count ){

        Write-Host "`tSite Collection $($sc.Url) is old" -ForegroundColor Red


}

Thursday, October 6, 2016

Cannot update Created By (Author) field through powershell

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
$SPWeb = Get-SPWeb "http://sharepoint";
$SPList = $SPWeb.GetList("http://sharepoint/Lists/Favorites");
$userName = "i:0#.w|[domain]\[username]";
$user = Get-SPUser -web $SPWeb -Identity $userName;

$SPListItem = $SPList.Items.Add();
$SPListItem["URL"] = "http://www.peakfinders.com";
$SPListItem["Author"] = $user;
$SPListItem.Update();

Thursday, March 17, 2016

Export the Subsite moved to site Collection Using PowerShell

Export the subsite


STSADM:

stsadm -o export -url "http://sharepointsite/sites/order/" -filename D:\backup.cmp -includeusersecurity -versions 4


Powershell:


Add-pssnapin microsoft.sharepoint.powershell

Import-SPWeb -identity "http://sharepointsite/sites/order/"  -path D:\backup.cmp -includeusersecurity  -force

Tuesday, March 15, 2016

How to get all default values for a document library

$FieldName = $list.Fields["NH Department"]
Write-Output $("NH Department - Default Value " + $FieldName.DefaultValue)