Sunday, 14 February 2016

Create Publishing Page using Powershell/ Create Pages from csv file



Below is the code which will create the Publishing page and added to Pages library . Here i am using Blankwebpart page layout and reading pageurls from text file and creating pages.

cls
asnp "*sh*"
$web=Get-SPWeb -Identity http://SP2013dev:3636/
$pubweb=[Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$file=Import-Csv -LiteralPath E:\MS\temp\pageurls.txt
$pageLayout=$pubweb.GetAvailablePageLayouts()|?{$_.Name -eq "BlankWebPartPage.aspx"}
foreach($page in $file.PageUrls)
{
$newPage=$pubweb.AddPublishingPage($page,$pageLayout);
$newPage.Update();
$newPage.CheckIn("Creating new page");
$newPage.ListItem.File.Publish("new page is created");
$web.Dispose();

Write-Host $page "Page is created" -ForegroundColor Green




text file(pageurls.txt):

PageUrls,
ISSAboutUs.aspx
ISSContactUs.aspx
ISSCustomerFirst.aspx
ISSVideos.aspx
ISSGenericCF.aspx
SolutionHub.aspx
ISSTechnotes.aspx



OutPut




Monday, 4 January 2016

Error while Configuring App Urls

The Subscription Settings service and corresponding application and proxy needs to be running in order to make changes to these settings. 




Solution:

Central Administration -> Application Management -> Service Applications -> Services on the Server


Click Start button of  

App Management Service and Microsoft SharePoint Foundation Subscription Settings Service 


























If you are still facing same issue then do an IISReset which will fix the issue.



Alternative We can RunPowerShell Scirpt to fix the issue if You haven't configured Service applications for AppManagement and Subscirption Service Settings 



cls
asnp "*sh*"


Get-SPServiceInstance |?{$_.TypeName -like  "App Management Service"| Start-SPServiceInstance

Get-SPServiceInstance | ? {$_.TypeName -like "Microsoft SharePoint Foundation Subscription Settings Service"| Start-SPServiceInstance

#Provide the service account as per your configuration 

$account=Get-SPManagedAccount -Identity CORP\Svc.AppsAccount

#configure Subscription Service Application for Sharepoint

$appPoolSubsvc=New-SPServiceApplicationPool -Name "SubscriptionServericeAppPool" -Account $account
$appSubSvc=New-SPSubscriptionSettingsServiceApplication -ApplicationPool $appPoolSubsvc -Name "Subscription Service Application" -DatabaseName SubscriptonServiceDB
$proxySubSvc=New-SPSubscriptionSettingsServiceApplicationProxy -ServiceApplication $appSubSvc
Write-Host "Subscirption Service Application Created"


$appPoolAppSvc= New-SPServiceApplicationPool -Name "AppManagementServiceAppPook" -Account $account
$appsMgmtSvc= New-SPAppManagementServiceApplication -ApplicationPool $appPoolAppSvc -Name "Apps Management Service" -DatabaseName "AppsDb"
$proxyAppSvc=New-SPAppManagementServiceApplicationProxy -ServiceApplication $appsMgmtSvc

Write-Host "Apps Management Service Application Created"

Create Service Applications Using Powershell


Below is the Powershell script which will create basic Service Applications for SharePoint 2013 



cls
asnp "*sh*"

Write-Progress -Activity "Instantiating Variable " -Status  "Done Variable Instantiation"

$databaseServerName = "toolsteam"
$saAppPoolName = "SharePoint AppPool Services"
$appPoolUserName = "Toolsteam0\spapppool"

   
## Service Application Service Names ##

$stateService="State Service Application"

$metadataSAName = "Managed Metadata Web Service"

$usageSAName = "Usage and Health Data Collection Service"

$userProfileSAName = "User Profile Synchronization Service"

   
$saAppPool = Get-SPServiceApplicationPool -Identity $saAppPoolName -ErrorAction SilentlyContinue

if($saAppPool -eq $null)
{

  Write-Progress -Activity "Creating Service Application Pool..." -Status  "Application Pool Creating Please Wait..."
 
  $appPoolAccount = Get-SPManagedAccount -Identity $appPoolUserName -ErrorAction SilentlyContinue

 

    if($appPoolAccount -eq $null)
  {
     
     Write-Progress -Activity "Creating AppPoolAccount" -Status  "AppPool Created" $appPoolAccount

     $appPoolCred = Get-Credential $appPoolUserName

     $appPoolAccount = New-SPManagedAccount -Credential $appPoolCred
  }
 
  New-SPServiceApplicationPool -Name $saAppPoolName -Account $appPoolAccount

  Write-Host $saAppPoolName "is Created "
     
}
# Create the  State Service application

Write-Progress -Activity "Creating State Service ." -Status  "State Service Creating Please Wait......"
 
New-SPStateServiceApplication -Name $stateService

Get-SPStateServiceApplication | New-SPStateServiceApplicationProxy -DefaultProxyGroup

Get-SPStateServiceApplication | New-SPStateServiceDatabase -Name "StateSterviceDB"

Get-SPDatabase| ? {$_.Type -eq "Microsoft.Office.Server.Administration.StateDatabase"} | Initialize-SPStateServiceDatabase


# Create the Usage service application


Write-Progress -Activity "Creating Usage Service and Proxy..." -Status  "Usage Service and Proxy...Creaated"

Write-Host "Creating Usage Service and Proxy..."

$serviceInstance = Get-SPUsageService

New-SPUsageApplication -Name $usageSAName -DatabaseServer $databaseServerName -DatabaseName "UsageDB" -UsageService $serviceInstance

$proxy=Get-SPServiceApplicationProxy | ? { $_.TypeName -eq "Usage and Health Data Collection Proxy"}

$proxy.Provision();

Write-Host $usageSAName "is Created"


# Create the Managed MetaData service application

Write-Progress -Activity "Managed MetaData Service and Proxy..." -Status  "Managed MetaData Service and Proxy...Creating Please Wait"

Write-Host "Creating Menaged MetaData Service Application"

$mmsapp = New-SPMetadataServiceApplication -Name "Managed Metadata Service" -ApplicationPool  $saAppPoolName -DatabaseName "ManagedMetadataDB"

# Create the service proxy
New-SPMetadataServiceApplicationProxy -Name "Managed Metadata Service Proxy" -ServiceApplication $mmsapp -DefaultProxyGroup

Write-Host $mmsapp "is created "


# Create the User Profile Service Application


Write-Progress -Activity "Creating UserProfile Service Application..." -Status  "Usage Service and Proxy...Creating Please Wait"

Write-Host "Creating UserProfile Service Application"

$upa = New-SPProfileServiceApplication -Name "User Profile Service" -ApplicationPool $saAppPoolName -ProfileDBName "ProfileDB" -SocialDBName "SocialDB" -ProfileSyncDBName "SyncDB"

# Create the service proxy

New-SPProfileServiceApplicationProxy -Name "User Profile Service Proxy" -ServiceApplication $upa -DefaultProxyGroup

Write-Host $upa "Is Created "






Wednesday, 23 December 2015

Disable LoopBackCheck


DisableLoopBack check to avoid multiple prompts while accessing sites



New-ItemProperty HKLM:\System\CurrentControlSet\Control\Lsa -Name "DisableLoopbackCheck" -value "1" -PropertyType dword

Create App Management Service Applications using Powershell



cls
asnp "*sh*"


Get-SPServiceInstance |?{$_.TypeName -like  "App Management Service"} | Start-SPServiceInstance

Get-SPServiceInstance | ? {$_.TypeName -like "Microsoft SharePoint Foundation Subscription Settings Service"} | Start-SPServiceInstance

#Provide the service account as per your configuration 

$account=Get-SPManagedAccount -Identity CORP\Svc.AppsAccount

#configure Subscription Service Application for Sharepoint

$appPoolSubsvc=New-SPServiceApplicationPool -Name "SubscriptionServericeAppPool" -Account $account
$appSubSvc=New-SPSubscriptionSettingsServiceApplication -ApplicationPool $appPoolSubsvc -Name "Subscription Service Application" -DatabaseName SubscriptonServiceDB
$proxySubSvc=New-SPSubscriptionSettingsServiceApplicationProxy -ServiceApplication $appSubSvc
Write-Host "Subscirption Service Application Created"


$appPoolAppSvc= New-SPServiceApplicationPool -Name "AppManagementServiceAppPook" -Account $account
$appsMgmtSvc= New-SPAppManagementServiceApplication -ApplicationPool $appPoolAppSvc -Name "Apps Management Service" -DatabaseName "AppsDb"
$proxyAppSvc=New-SPAppManagementServiceApplicationProxy -ServiceApplication $appsMgmtSvc

Write-Host "Apps Management Service Application Created"

Monday, 30 November 2015

Microsoft SharePoint is not supported in 32-bit process. Please verify that you are running in a 64-bit executable.






Solution :


In visual Studio Go to Project Properties ->Build  -> Platform target -Any CPU  and 

Click on Build which will fix the issue.












Copy files and Folders in SharePoint from One Site to anonther Site

Below PowerShell Script to copy files and folders from one Site to anonther through powershell

cls

asnp "*sh*"

write-Host "Please Provide the Source web site url and Desstination url"-foregroundcolor white -backgroundcolor blue
##
$SourceWebURL = read-host "Enter Source WebURL:"
$DestinationWebURL = read-host "Enter Destination WebURL:"
##
write-Host "Please Provide the Source library title and Destination library title"-foregroundcolor white -backgroundcolor blue
##
$SourceLibraryTitle = read-host "Enter Source LibraryTitle:"
$DestinationLibraryTitle = read-host "Enter Destination LibraryTitle:"
##
write-output "Started...";
##
$sWeb = Get-SPWeb $SourceWebURL
$sList = $sWeb.Lists | ? {$_.Title -eq $SourceLibraryTitle}
$dWeb = Get-SPWeb $DestinationWebURL
$dList = $dWeb.Lists | ? {$_.title -like $DestinationLibraryTitle}

$AllFolders = $sList.Folders
$RootFolder = $sList.RootFolder
$RootItems = $RootFolder.files

foreach($RootItem in $RootItems)
{
    $sBytes = $RootItem.OpenBinary()
    $dFile = $dList.RootFolder.Files.Add($RootItem.Name, $sBytes, $true)

    $AllFields = $RootItem.Item.Fields | ? {!($_.sealed)}

    foreach($Field in $AllFields)
    {
        if($RootItem.Properties[$Field.Title])
        {
            if(!($dFile.Properties[$Field.title]))
            {
                $dFile.AddProperty($Field.Title, $RootItem.Properties[$Field.Title])
            }
            else
            {
                $dFile.Properties[$Field.Title] = $RootItem.Properties[$Field.Title]
            }
        }
    }
    $dFile.Update()
}

foreach($Folder in $AllFolders)
{
    #Remove-Variable ParentFolderURL
        $varExists = Get-Variable ParentFolderURL -ErrorAction SilentlyContinue

    if($varExists -ne $null){

           Remove-Variable ParentFolderURL  }
    $i = 0
    
    $FolderURL = $Folder.url.Split("/")
        
    while($i -lt ($FolderURL.count-1))
    {
    $ParentFolderURL = "$ParentFolderURL/" + $FolderURL[$i]
    $i++
    }
    
    $CurrentFolder = $dList.Folders | ? {$_.url -eq $ParentFolderURL.substring(1)}
    if(!($CurrentFolder.Folders | ? {$_.name -eq $Folder.Name}))
    {
        $NewFolder = $dlist.Folders.Add(("$DestinationWebURL" + $ParentFolderURL), [Microsoft.SharePoint.SPFileSystemObjectType]::Folder, $Folder.name)
        $NewFolder.update()
    }
    else
    {
        $NewFolder = $dList.Folders | ? {$_.name -eq $Folder.Name}
    }
    $AllFiles = $sList.Items
    $sItems = $Folder.folder.Files
    
    if($Folder.Folder.Files.count -gt 0)
    {
        foreach($item in $sItems)
        {
            
            #$Relative = ($Item.ServerRelativeUrl).substring(1)
            $Relative = ($Item.Url)
            $TargetItem = $AllFiles | ? {$_.URL -eq $Relative}
            $sBytes = $TargetItem.File.OpenBinary()
            $dFile = $Newfolder.Folder.Files.Add($TargetItem.Name, $sBytes, $true)
            $AllFields = $TargetItem.Fields | ? {!($_.sealed)}
            
            foreach($Field in $AllFields)
            {
                if($TargetItem.Properties[$Field.Title])
                {
                    if(!($dFile.Properties[$Field.title]))
                    {
                        $dFile.AddProperty($Field.Title, $TargetItem.Properties[$Field.Title])
                    }
                    else
                    {
                        $dFile.Properties[$Field.Title] = $TargetItem.Properties[$Field.Title]
                    }
                }
            }
            $dFile.Update()
        }
    }
}
Write-Host "All Files are moved successfully" -foregroundcolor green