Tag Info

Hot answers tagged

11

or simply: $site = Get-SPSite http://YourSharePointSite $site.AllWebs.Count


4

if ($ver.Version.Major -gt 1) {$host.Runspace.ThreadOptions = "ReuseThread"} if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) { Add-PSSnapin "Microsoft.SharePoint.PowerShell" } $sites = Get-SPSite <SiteCollectionUrl> $noOfWebs = 0 foreach ($web in $sites.AllWebs) { $noOfWebs++ } If ($sites ...


4

Please follow steps given below to ensure SharePoint Administration Services is available: Click on Start->Run->Services.msc. Search for "SharePoint 2010 Administration" service and make sure Status is Started. If it is not enabled, start the service and re-execute the command.


4

You can check-in all checked out documents and then delete $web = Get-SPWeb http://weburl $folder = $web.GetFolder("Library Name") $folder.Files | Where { $_.CheckOutStatus -ne "None" } | ForEach { $_.CheckIn("Checked in") } $web.Dispose() Update You can fill in a temporary value to those fields. Then do check-in. Then delete $web = ...


3

You can use Custom Objects and use Export-CSV as below. This approach will give you more flexibility like opening in Excel and Sort, Filter etc. Also you can easily add additional fields to output. Add-PSSnapin Microsoft.SharePoint.Powershell -ea 0; $web = get-spweb 'http://tvstg01/kb/customerservice/' $list = $web.lists['Customer Service']; ...


3

Wouldn't you need to make this: ($link.url -like '.doc' -or $link.url -like '.docx' -or $link.url -like '.pdf') like this: ($link.url -like '*.doc' -or $link.url -like '*.docx' -or $link.url -like '*.pdf')


3

Option 1 How to add/upload publishing page layout via CSOM in PowerShell: [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") Function Get-ClientContext([string]$Url,[string]$UserName,[string]$Password) { $SecurePassword = $Password | ...


3

Right after you add the file: $item = $spFile.Item; $item["TextOrChoiceColumnInternalName"] = "New Value" $spUser = Get-SPUser -Identity "domain\username" -Web $spSourceWeb; $item["UserFieldInternalName"] = $spUser; $item.SystemUpdate($false); Use SystemUpdate($false) if you don't want to increase the version of the item.. To check in a file use: ...


3

I created this simple PowerShell script to calculate for a single Document Library what the size in MB is for all the files inside: $total = $null; ((get-spweb http://WebApplication/SiteCollection/subsite/).lists | Where-Object {$_.title -eq "Library Title"}).items | foreach {$total+= $_.file.length}; $total /1MB Before you can use the script you need to ...


3

Using the following code, within the SharePoint Management Shell, you can get the count of Web Applications in the Farm, Site Collections in Web Application, Sites in Site Collection. Write-Host "Web Applications in Farm" $WebApplications = Get-SPWebApplication $WebApplications | Measure-Object | Format-List Count ForEach($WebApplication in ...


2

Try Add-PSSnapin Microsoft.SharePoint.PowerShell; $files = ([System.IO.DirectoryInfo] (Get-Item "C:\DP")).GetFiles(); $templateFolder = "content web parts"; $site = Get-SPSite http://siteurl $web = $site.OpenWeb(); $folder = $web.GetFolder("_catalogs/masterpage/display templates/" + $templateFolder); foreach($file in $files) { $stream = ...


2

You should do it recursively as below function DeleteWeb([Microsoft.SharePoint.SPWeb] $web) { $webs = $web.GetSubwebsForCurrentUser() foreach($w in $webs) { DeleteWeb($w) $w.Dispose() } Remove-SPWeb $web -Confirm:$false } $web = Get-SPWeb "http://weburl" DeleteWeb $web $web.Dispose()


2

If your web part is stored in V3 format (http://schemas.microsoft.com/WebPart/v3) then the following example demonstrates how to get web part property: $path="c:\Search Box.webpart" $propertyName = "Title" #replace to your property name UrlWebPart [xml]$webPart = Get-Content $path $property = $webPart.webParts.webPart.data.properties.property | ...


2

Replace Write-Host $file.name $link.url with "$($file.name) $($link.url)" | Tee-Object test.txt -Append This will output the text to both the screen and test.txt (remember to clear this first)


2

You can also do the same using $ext = [System.IO.Path]::GetExtension($link.url) if($ext -eq '.doc' or $ext -eq '.docx' or $ext -eq '.pdf') { #file found }


1

There is an XML type in PowerShell. Exploring XML Document by Using the [XML] Type Accelerator Define $a as [XML]$a = $item["XMLField"]; Now you would be able to lookup set the value of NodeImLookingFor as $a.NodeImLookingFor = "New Value"; Regards


1

You're missing * in all the file extension tests


1

Run the following code to get in txt file Add-PSSnapin Microsoft.SharePoint.Powershell -ea 0; $output="" $web = get-spweb 'http://tvstg01/kb/customerservice/' $list = $web.lists['Customer Service']; foreach($file in $list.items){ $links = $file.ForwardLinks; foreach($link in $links){ ...


1

I resolved my problem : $webUrl = "http://site.fr/" $library = "librarieName" $spSite = new-object Microsoft.SharePoint.SPSite($webUrl) $w = $spSite.OpenWeb() $l = $w.Lists[$library] $resultHashtable = @{} foreach ($listItem in $l.Items) { Write-Host " Content: " $listItem.ID foreach ($attachment in $listItem.Attachments) { ...


1

You can use PowerShell to get this information Function GetFiles($folder) { Write-Host $folder.Name foreach($file in $folder.Files) { Write-Host $file.Name } foreach ($subFolder in $folder.SubFolders) { GetFiles($Subfolder) } } $web = Get-SPWeb http://weburl $list = $web.Lists["ListName"] ...


1

Try this: $currentSite = Get-SPSite -Identity $siteFollowed.Uri.AbsoluteUri foreach($web in $currentSite.AllWebs){ $web.Url version is $web.UIVersion #4 or 15 } }


1

Since SharePoint 2013/Online supports a sets of APIs, CSOM or REST APIs could be consumed in PowerShell for that purpose. How to stop permissions inheritance for a List in SharePoint Online Prerequisites: SharePoint Online Client Components SDK The example below shows how to assign unique permissions for a list using CSOM API in PowerShell: ...


1

From your command, looks like their is some error.You have to provide the complete path of PSConfig and also use -ArgumentList instead of ps-ArgumentList. Start-Process "path of file\PSConfig.exe" -ArgumentList "-cmd upgrade -inplace v2v -passphrase FarmPassPhrase -force -wait" -Wait If their is not such requirement then you can directly run the psconfig ...


1

Thanks to user19952 I was able to make the connection. Yes, it was true! Powershell was running under a different user account then the one I had logged on. This was because I am sharing my environment with other people and we are using the same account. So someone must have logged in on Powershell using a different account. From now on I will always ...


1

At a glance, if you do not wish to add permissions to the group, don't! Just do this part: foreach($groupName in $DisciplineGroups) { if ($mRootWeb.SiteGroups[$groupName] -ne $null) { Write-Host "Group "$($groupName)" already exists!" Break; } else { $mRootWeb.SiteGroups.Add($groupName, ...


1

You can get the list of content types associated with a List. And the first one is the default one. $webs = Get-SPSite http://siteurl | Get-SPWeb foreach ($web in $webs) { foreach ($list in $web.lists) { if($list.ContentTypes.Count > 0) { Write-Host "Default Content Type = " + $list.ContentTypes[0].Name } ...


1

In order to delete a site that has subsites using PowerShell, as shown below: # Completely deletes the specified Web (including all subsites) function RemoveSPWebRecursively( [Microsoft.SharePoint.SPWeb] $web) { Write-Debug "Removing site ($($web.Url))..." $subwebs = $web.GetSubwebsForCurrentUser() foreach($subweb in $subwebs) { ...


1

You can update the associated content type by this indirect route. Suppose you have a content type name $contentTypeName, a web $web, and the list item of your page layout, $item. $item.Properties["PublishingAssociatedContentType"] = ";#" + $contentTypeName + ";#" + $web.AvailableContentTypes[$contentTypeName].Id.ToString() + ";#" $item.Update() ...


1

You can do it using below script $site = Get-SPSite http://siteurl $site.LastContentModifiedDate


1

You should be able to use this: Set-SPOUser -Site "https://oursp.sharepoint.com/sites/sitecoll" -IsSiteCollectionAdmin $true -LoginName "c:0-.f|rolemanager|s-1-5-21-112313..."



Only top voted, non community-wiki answers of a minimum length are eligible