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

Wednesday, September 21, 2016

How to move Child Subsite to another site collection using PowerShell


Add SharePoint snapin

Add-PSSnapin Microsoft.SharePoint.PowerShell –ea SilentlyContinue

Set variables - FYI exportfolder will throw an error if folder is already created.

$exportfolder = "E:\backup\NAME" $exportfile = "\s.cmp" $exportsite = "http://test/hr/site 101" $exportlocation = $exportfolder+$exportfile $importlocation = "http://test2/hr/site 101"

Get export site's template

$web = Get-SPWeb $exportsite $webTemp = $web.WebTemplate $webTempID = $web.Configuration $webTemplate = "$webTemp#$webTempID" $web.Dispose()

Create export folder

$null = New-Item $exportfolder -type directory

Export site

Export-SPWeb $exportsite –Path $exportlocation -IncludeUserSecurity -IncludeVersions 4 Write-host "$exportsite has been exported to $exportlocation"

Create new site ready for import

$null = New-SPWeb $importlocation -Template "$webTemplate" Write-host "$importlocation created ready for import"

Import site

Import-SPWeb $importlocation –Path $exportlocation -IncludeUserSecurity –UpdateVersions 2 Write-host "$exportsite has been imported to $importlocation" -foregroundcolor "Green"

Friday, September 16, 2016

How to get attachments from SharePoint list with PowerShell?

SharePoint 2013 it works

$webUrl = "http://peakfinder/"    
$library = "Product Information"
$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)
    {
        $file = $w.GetFile($listItem.Attachments.UrlPrefix + $attachment)
        $linkAttachment = "http://peakfinder/" + $file.ServerRelativeUrl
        Write-Host "http://peakfinder/"$file.ServerRelativeUrl
        if($linkAttachment){
        $resultHashtable.Add($listItem.ID, $linkAttachment)
        }    
    }    
}
#Export CSV
$resultHashtable.GetEnumerator() | Sort-Object -Property Name -Descending |
Select-Object -Property @{n='SiteURL';e={$_.Name}},Value |
Export-Csv -Path Attachments.csv -NoTypeInformation

How to enable the officewebapps in Sharepoint 2013 using Powershell Script

Get-OfficeWebAppsFarm

Powershell Script
$owaFarm = Get-OfficeWebAppsFarm;
$owaFarm .OpenFromUrlEnabled = $true;

Tuesday, July 19, 2016

Find all users who have not added a picture to their Mysite Profile

[void][reflection.assembly]::Loadwithpartialname("Microsoft.Office.Server") | out-null
$site=new-object Microsoft.SharePoint.SPSite("https://peakfinders") #Central Admin site
$servercontext=[Microsoft.Office.Server.ServerContext]::GetContext($site)
$site.Dispose() # clean up
$upm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($servercontext)
$pc = $upm.GetEnumerator()
foreach($p in $pc){$v = $p["PictureUrl"].Value;if($v -eq $null){Write-Host $p["AccountName"].ToString()"doesn's have a picture set."}}

#Optional, display all the Picture URL's
$pc = $upm.GetEnumerator();
foreach($p in $pc){$p["PictureUrl"].Value}

Thursday, March 17, 2016

WSP gets stuck in "Deploying"


  • stsadm -o execadmsvcjobs on the server running Central Admin
  • Install-SPSolution has only the -Force, 
  • Check for Sharepoint 2013 Timer service






Add-SPSolution –LiteralPath "d:solution.wsp" 

install solution and we executed the following command:

Install-SPSolution -Identity "solution.wsp" -WebApplication http://peakfinders.com/  –GACDeployment