Skip to main content

Posts

Showing posts with the label Powershell

Create a SharePoint Online Site - Office 365 using Powershell

Create a SharePoint  Online Site - Office 365 using Powershell # Usage #       .\create-site-csom.ps1 -siteTitle "new site2" -siteUrl "newsite2" -cred $false -parent "https://pravahaminfo.sharepoint.com/teams/appdev1/" # #       .\create-site-csom.ps1 -siteTitle "new site2" -siteUrl "newsite2" -cred $true -parent "https://pravahaminfo.sharepoint.com/teams/appdev1/" #               Will ask for Credentials Param(     [Parameter(Mandatory=$true)]  [string] $parent,  [Parameter(Mandatory=$true)]  [string] $siteTitle, [Parameter(Mandatory=$true)] [string] $siteUrl, [string] $siteDescription,     [string] $template = "STS#0",     [bool] $cred #Use custom Credentials ) #Clear-Host Write-Host "Initializing..." $resources = split-path $script:MyInvocation.MyCommand.Definition if(-not $(Test-Path "$resources\bin")) ...

Get List of Site owners from all web applications in SharePoint using Powershell

List of Site owners from all web applications in SharePoint using Powershell Add-PSSnapin "Microsoft.SharePoint.Powershell" function CreateReportObject($url = $null, $title = $null, $desc = $null, $IsRoot = $null, $groupname = $null, $loginname = $null, $dg = $null, $email = $null, $ucount = $null, $created = $null, $farm = $null,$isreadonly = $null)  {  $newreportobj = new-object psobject          $newreportobj | add-member noteproperty -name "URL" -value $url  $newreportobj | add-member noteproperty -name "Title" -value $title  $newreportobj | add-member noteproperty -name "Description" -value $desc  $newreportobj | add-member noteproperty -name "IsRootWeb" -value $IsRoot          $newreportobj | add-member noteproperty -name "Groups" -value $groupname         $newreportobj | add-member noteproperty -name "Owners" -value $loginname $newreportobj | add-member notepr...

Get List of Site collection owners from all web applications in SharePoint using Powershell

List of Site collection owners from all web applications in SharePoint using Powershell Add-PSSnapin "Microsoft.SharePoint.Powershell" function CreateReportObject($url = $null, $title = $null, $loginname = $null, $dg = $null, $created = $null, $isreadonly = $null, $email = $null) { $newreportobj = new-object psobject          $newreportobj | add-member noteproperty -name "URL" -value $url  $newreportobj | add-member noteproperty -name "Title" -value $title         $newreportobj | add-member noteproperty -name "Owners" -value $loginname $newreportobj | add-member noteproperty -name "DomainGroups" -value $dg         $newreportobj | add-member noteproperty -name "Email" -value $email $newreportobj | add-member noteproperty -name "Created" -value $created  $newreportobj | add-member noteproperty -name "Is Read-Only" -value $isreadonly         return ($newreportobj)...

Get SharePoint List Item Version History

Here is a powershell script you can use to get csv output of version history from SharePoint 2010 list. The output includes changes to individual item fields as viewable from item version history. $web  = Get-SPWeb http://pravahaminfo.com/web  $list = $web.Lists["Document Library"] # Name of the List?library $csvFile = "C:\ListItemVersionHistory.csv" # Save folder Location function GetFieldValue([Microsoft.SharePoint.SPField]$field, [Microsoft.SharePoint.SPListItemVersion]$currentVersion)  {      if(($field.Type -eq "User") -and ($currentVersion[$field.Title] -ne $null))      {          $newUser = [Microsoft.SharePoint.SPFieldUser]$field;          $fieldStr = $newUser.GetFieldValueAsText($currentVersion[$field.Title])          $fieldStr = "$($field.Title): $fieldStr"      }      elseif(($field.Type -eq "...

Copy List Item to other list in SharePoint using Powershell

#  In the below code, there are five custom variables ## $srcListSiteUrl : Site url where the source list is present ## $SourceListName : Name of the source list ## $dstListSiteUrl : Site url where the destination list is present (In the above code both lists are in the same site) ## $DestinationListName : Name of the destination list ## $keyColumnInternalName : Column name with which we have to check whether to insert or update. ## Note, in the above example $keyColumnInternalName value is ‘Title’. It is Text type. So, the CAML query variable $camlQuery is constructed in that way. ## If you have different data type column which you want to use as a reference column, you have to change the variable accordingly as the column type. ### Remove-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue     try     {     $srcListSiteUrl = "http://contoso...

Delete a List Item from a SiteCollection in SharePoint using Powershell

$site = Get-SPSite "http://contoso:1212/mysites/" $web = $site.rootweb $list = $web.Lists["Market"] $caml="" #optional filter #<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">Form</Value></Eq></Where>" $query=new-object Microsoft.SharePoint.SPQuery $query.ViewAttributes = "Scope='Recursive'" $query.Query=$caml $items=$list.GetItems($query) Write-Host $items.Count $items | % { $list.GetItemById($_.Id).Delete() } $web.Dispose() $site.Dispose()

Import List Items in SharePoint using Powershell

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue  $csvVariable= Import-CSV -path "http://sp2010.contoso.com/finance/" # Destination site collection $WebURL = "http://sp2010.contoso.com/sites/Utility/"  # Destination list name $listName = "Inventory"  #Get the SPWeb object and save it to a variable $web = Get-SPWeb -identity $WebURL  #Get the SPList object to retrieve the list $list = $web.Lists[$listName]  #Get all items in this list and save them to a variable  $items = $list.items        #loop through csv file foreach($row in $csvVariable) {     $updated = 0     #loop through SharePoint list     foreach($item in $items)     {         if($item["ID #"] -eq $row."ID #")              {                  $updated++          ...