Monday, March 27, 2017

Show Page View Count based on location

Create List Structure:

List Title : "PageAnalytics"

Columns Type

Title(Country) (Single Line of Text)

PageTitle (Single Line of Text)

UserID (Number)

Script to Save Current User Location on Page View and Also Fetch Page View Details

});//Fetching Current Users Location from site 'http://freegeoip.net'
$.getJSON("http://freegeoip.net/json/", function(data) {
var countryName = data.country_name;
//In case any other details need to be saved or displayed other than country name
/*
var country_code = data.country_code;
var ip = data.ip;
var time_zone = data.time_zone;
var latitude = data.latitude;
var longitude = data.longitude;
*/
storeCurrentUser(countryName);
getPageViews();
});
//Adding Page View Detail of current user to List
function StoreCurrentUser(countryName){
var currentPage=$(document).attr('title');
var currentUser=_spPageContextInfo.userId;
var data = {
    __metadata: { 'type': 'SP.Data.PageAnalyticsListItem' },
    Title: countryName,
    PageTitle: currentPage,
    UserID: currentUser
};
$.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('PageAnalytics')/Items",
    type: "POST",
    headers: {
        "accept": "application/json;odata=verbose",
        "X-RequestDigest": $("#__REQUESTDIGEST").val(),
        "content-Type": "application/json;odata=verbose"
    },
    data: JSON.stringify(data),
    success: function (data) {
        console.log(data);
    },
    error: function (error) {
        alert(JSON.stringify(error));
    }
}
//Fetching current Page view from list filtered by Page Title
function getPageViews(){
var currentPage=$(document).attr('title');
var countryArray=[];
var userArray=[];
var viewCount={};
$.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('PageAnalytics')/Items?$orderby=Title&$filter=PageTitle eq " + currentPage,
    type: "GET",
    headers: {
        "accept": "application/json;odata=verbose",
    },
    success: function (data) {        
        console.log(data.d.results);
        $.each(data.d.results,function(i,val){
            //for unique Page Unique User Count                
            if(userArray.indexOf(val["UserID"]) < -1 && countryArray.indexOf(val["Title"]) < -1){
                userArray.push(val["UserID"]);
                countryArray.push(val["Title"]);
                viewCount[val["Title"]]={
                    Country : val["Title"],
                    Count : 1;
                }
            }
            else{
                viewCount[val["Title"]]["Count"]=viewCount[val["Title"]]["Count"]+1;
            }
            //Unique page and Non Unique Users
            /*if(userArray.indexOf(val["UserID"]) < -1 && countryArray.indexOf(val["Title"]) < -1){
                userArray.push(val["UserID"]);
                countryArray.push(val["Title"]);
                viewCount[val["Title"]]={
                    Country : val["Title"],
                    Count : 1;
                }
            }
            else{
                viewCount[val["Title"]]["Count"]=viewCount[val["Title"]]["Count"]+1;
            } */
        });
        //final Page wise count can be found here
        console.log(viewCount);
    },
    error: function (error) {
        alert(JSON.stringify(error));
    }
});
}

upgrade workflow manager


  1. install Service Bus 1.0 CU 1 on all workflow servers using web platform installer. Reboot
  2. install Workflow Manager 1.0 Refresh on all workflow servers using web platform installer Reboot
  3. install Workflow Manager Client 1.0 Refresh on all workflow servers using web platform installer (Do we need to install this tool in SharePoint Servers too)
  4. Run (Register-SPWorkflowService) in SharePoint Servers.

Thursday, March 16, 2017

sharepoint Powershell migrate users in a web application

[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges({
param([string]$url = "http://sharepointsite/", `
[string]$oldprovider = `
"keystoneuser", `
[string]$newprovider = `
"i:0ǵ.t|keystone sts|radiant\")

add-pssnapin microsoft.sharepoint.powershell -EA 0

# Get all of the users in a site
#$users = get-spuser -web $url -Limit "11000"
$csvFile = "C:\Users\Users.csv"
# Loop through each of the users in the site
Import-Csv $csvFile | ForEach-Object{
# Create an array that will be used to split the user name from the domain/membership provider
$a=@()
$username = $_.oldlogin
$a = $username.split(":")
$userloginprovider = $a[0]
$displayname = $a[1]
Write-Host "Old Username: $username."
# Create the new username based on the given input
$newalias = $newprovider + $displayname
$user = Get-SPUser -Identity $username -Web http://
sharepointsite/ -EA "SilentlyContinue"
if($user -notlike "")
{
Move-SPUser –Identity $user -NewAlias "$newalias" -IgnoreSID -Confirm:$false -EA "SilentlyContinue"
Write-Host "User Changed to $newalias"
}
}
}); 




To migrate user in farm use the following,


$farm.MigrateUserAccount( $_.oldlogin, $_.newlogin, $false )

SharePoint: How to change the default home page

$site = Get-SPSite http://peakfinder/sites/site
$web = $site.RootWeb
  (or $web = $site.OpenWeb("site")
$folder = $web.RootFolder
$folder.WelcomePage = "SitePages/home.aspx"
  (or  $folder.WelcomePage = "default.aspx")
  (or  $folder.WelcomePage = "SiteAssets/myhome.aspx")
$folder.update()
$web.Dispose()
$site.Dispose()

Local accounts should only be used in standalone mode SharePoint 2010 / 2013 run PSConfig

I was trying to install SharePoint Server 2010. I ran into the following error.

Local accounts should only be used in standalone mode.

To get around this, you will need to use PSConfig  Command to create your Content Database.

To use PSConfig  command you need run command prompt with run as Administrator.

Then go the following location:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN

PSCONFIG.EXE -cmd configdb -create -server 5282-SUSHIL -database sharepoint_2013_config -user 5282\administrator -password password -passphrase password@123 -admincontentdatabase sharepoint2013_admincontent

*******************Worked*****************************

 

example: that worked for me.

psconfig -cmd configdb -create -server WIN-H0QE54APLD0 -database sharepoint_2013_config -user administrator -password admin@123 -passphrase pass@123 -admincontentdatabase sharepoint2010_admincontent

IT will run the task from 1 to 3 step only

then you need to run SharePoint Configuration Wizard.