Monday, 5 September 2016

PowerShell Real Time Examples

Below are some of the Real Time Examples of how SharePoint can saved, analysed or managed with the help of PowerShell:

1. Getting the Active Directory properties of SharePoint User.

SharePoint stores the user details in the form of claim token which needs to be decoded when we are trying to pull the details of user like the Site Collection of a Site Collection Administrator or Owner.
Here is the sample script which came to the rescue , instead of writing huge lines of code in C# in Visual Studio. Get-SPUser is fantastic if the User Profile stores all the AD details.

$ownerSP=Get-SPSiteAdministration -Url "http://w15-sp"|select OwnerLoginName
$m = [Microsoft.SharePoint.Administration.Claims.ClaimProviderManager]::Local
$ownerAD=$m.DecodeClaim($ownerSP.OwnerLoginName)
Get-ADUser -Identity $ownerAD -Properties * | select department,county


Thursday, 30 June 2016

Add Operations in SharePoint On Premise with POwerShell

Help Add-SPProjectLogLevelManager -examples
#Add Project entity to Project Sharepoint Site
Add-SPProjectLogLevelManager -Url http://w15-sp/pwa -EntityType Project -EntityUID "0798BF6A-F248-4F0F-8957-4D73993265BC"-LogLevel Verbose -Comments "xyz"
Get-SPProjectLogLevelManager -Url http://w15-sp/pwa
help Add-SPRoutingMachineInfo -examples
#Add routing target to specified identity to farm
$web = Get-SPWebApplication -Identity "http://w15-sp"
$rm = Get-SPRequestManagementSettings -Identity $web
Add-SPRoutingMachineInfo -RequestManagementSettings $rm -Name "w15-dc" -Availability Available
Get-SPRoutingMachineInfo -RequestManagementSettings $rm

#Adds a new machine pool.
 $web=Get-SPWebApplication -Identity "http://w15-sp"
   
 $rm=Get-SPRequestManagementSettings -Identity $web
   
 Add-SPRoutingMachinePool -RequestManagementSettings $rm -Name "w15-dc"
 Get-SPRoutingMachinePool -RequestManagementSettings $rm
   
   
help Add-SPRoutingRule -examples
# This examples adds a routing rule to the farm by using the $rm 
#   variables.
Add-SPRoutingRule -RequestManagementSettings $rm -Name "SampleRule"
Get-SPRoutingRule -RequestManagementSettings $rm

Note: The following content is in progress and please DO NOT use in production

Add-SPRoutingRule -RequestManagementSettings $rm -Name "SampleRule"

Get-SPRoutingRule -RequestManagementSettings $rm

#Add Scaleout database(IN Progress)

$appService = Get-SPServiceApplication |?{$_.DisplayName -like  "*App Management*"}

Add-SPScaleOutDatabase -ServiceApplication $appService -DatabaseName "sample"

 $appServiceProxy=Get-SPServiceApplicationProxy| ?{$_.DisplayName -like  "*App Management*"}

 Add-SPServiceApplicationProxyGroupMember -Identity 66c958d1-d10a-4880-bfc3-8b2646b8e4cd -Member fc413acb-f0b1-4617-b2f3-f2ef93c7f8bb

 Get-SPServiceApplicationProxyGroup

#Add new account

Add-SPSecureStoreSystemAccount -AccountName "contoso\garthf"

Get-SPSecureStoreSystemAccount

#Adds a user to the SharePoint_Shell_Access role for the specified database.
<#This example adds a new user named User1 to the SharePoint_Shell_Access role in 
    the farm configuration database only, and also ensures the user is added to the 
    WSS_Admin_WPG local group on each server in the farm.
    #>
Add-SPShellAdmin -UserName "contoso\garthf"

    
#This example adds a new user named garthf to the SharePoint_Shell_Access role in 
    #the farm configuration database only, and also ensures the user is added to the 
    #WSS_Admin_WPG local group on each server in the farm.

Add-SPShellAdmin -UserName CONTOSO\garthf
    
#This example adds a new user named User1 to the SharePoint_Shell_Access role in 
 # both the specified content database and the configuration database by passing a 
 #  database GUID to the cmdlet.   
$spDatabase = Get-SPContentDatabase |?{$_.Name –like “*Project*”}    
Add-SPShellAdmin -UserName CONTOSO\User1 -database $spDatabase.ID 
    
#This example adds a new user named garthf to the SharePoint_Shell_Access role in 
  #  both the specified Central Administration content database and the configuration 
  #  database.    
Get-SPDatabase | Where-Object {$_.WebApplication -like 
    "SPAdministrationWebApplication"} | Add-SPShellAdmin CONTOSO\garthf
    
   # This example adds a new user named garthf  to the SharePoint_Shell_Access role of 
    #both the specified content database and the configuration database by passing the 
    #name of the database to the cmdlet.

Get-SPDatabase | ?{$_.Name -eq "WSS_Content"} | Add-SPShellAdmin -Username 
    CONTOSO\garthf

Tuesday, 28 June 2016

Add/Update Operations on User Profile

#Turn on Security Trimming in Service Application
$upProxy = Get-SPServiceApplicationProxy |?{$_.DisplayName -like "*Profile*"}
Add-SPPluggableSecurityTrimmer -UserProfileApplicationProxyId $upProxy.ID
Get-SPPluggableSecurityTrimmer -UserProfileApplicationProxyId $upProxy.ID
Get-Help Add-SPPluggableSecurityTrimmer -examples

#Add Profile Leader
Add-SPProfileLeader -ProfileServiceApplicationProxy $upProxy -Name "contoso\alexd"
Get-SPProfileLeader -ProfileServiceApplicationProxy $upProxy
#Add User Profiel from different domain
Get-Help Add-SPProfileSyncConnection -examples
Add-SPProfileSyncConnection -ProfileServiceApplication $upProxy`
    -ConnectionForestName "fabrikam.com" -ConnectionDomain "Fabrikam" -ConnectionUserName "Testupa" `
    -ConnectionPassword convertto-securestring "Password1" -asplaintext -force `
    -ConnectionSynchronizationOU "OU=SharePoint Users,DC=fabrikam,DC=com"`

Saturday, 25 June 2016

Adds a user agent to a farm


Add-PSSnapin "Microsoft.SharePoint.PowerShell"                                  

Get-Help Add-SPInfoPathUserAgent -examples                                      

Get-SPInfoPathUserAgent                                                        

Add-SPInfoPathUserAgent -Name "something"

#View new agent

Get-SPInfoPathUserAgent

Thursday, 23 June 2016

Display all the lists in a SharePoint Site collection

This is a very simple set of code in PowerShell to find all the lists in SharePoint which are not default/hidden for all web sites under a site collection.


http://contoso.sharepoint.com


$spSite = Get-SPSite -Identity http://contoso.sharepoint.com

$spWebs = $spSite.AllWebs




Get-Date


foreach($spWeb in $spWebs)



{

$spWebTitle = $spWeb.Title

"Displaying Lists in Site::"+$spWebTitle

$spLists = $spWeb.Lists

foreach ($spList in $spLists)



{

$spList.Title



}

"List Count in site ::"+$spWebTitle + "::" + $spLists.Count

#Get-Date;



}



Tuesday, 14 June 2016

Creating a SharePoint Education Site

As I was exploring the SharePoint PowerShell commandlets, I got stuck with an interesting command related to SharePoint Education site.Add-SpEdu...
[In Progress[

References
http://blog.furuknap.net/sharepoint-education-installing-and-configuring

CRUD Operations in SharePoint using PowerShell

The following is a series of commands in SharePoint using PowerShell helping to perform many administrative tasks or even development tasks with ease.

Get-HElp Add-SPAppDeniedEndpoint -examples
#Stop Apps from accessing an endpoint
Add-SPAppDeniedEndpoint -Endpoint "_vti_bin/contoso/service.asmx"
Get-SPAppDeniedEndpointList
Get-Help Add-SPClaimTypeMapping -Examples
#Add a claim-https://technet.microsoft.com/en-us/library/ff607650.aspx
#Note: the New-SPClaimTYpeMapping worked and Add-SPClaimTYpeMapping is an example from msdn site.
Get-TrustedIdentityTokenIssuer -Identity "LiveIDSTS" | Add-SPClaimTypeMapping -IncomingClaimType "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier" -IncomingClaimTypeDisplayName "PUID" -LocalClaimType "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/thumbprint"
$map1 = New-SPClaimTypeMapping -IncomingClaimType "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" -IncomingClaimTypeDisplayName "EmailAddress" -SameAsIncoming
Get-Help Add-SPDiagnosticsPerformanceCounter -examples
<#This example adds the _Total instance of the counter % Processor Time in the
    category Processor on database servers.#>
Add-SPDiagnosticsPerformanceCounter -category Processor -counter "%Processor Time" -instance "_Total" -databaseserver
Get-SPDiagnosticsPerformanceCounter
Get-Help Add-SPDistributedCacheServiceInstance -examples -Online
#Add Distributed Cache
Add-SPDistributedCacheServiceInstance