Tuesday, December 26, 2017

Provider Hosted HighTrust Step by Step

1. Start Services in Central Admin
1. App Management
2. Subscription service
3. UPS

2. Create Web Service Applications in CA
1. UPS
2. App Management

3. Using Power Creae Subscription Proxy service Applications
$account = Get-SPManagedAccount "gdpr/tcadmin"
$appPoolSubSvc = New-SPServiceApplicationPool -Name SettingsServiceAppPool -Account $account
$appSubSvc = New-SPSubscriptionSettingsServiceApplication -ApplicationPool $appPoolSubSvc -Name SPSubscriptionSettingsServiceApplication -DatabaseName "SP-SubscriptionSettingsDB"
$proxySubSvc = New-SPSubscriptionSettingsServiceApplicationProxy -ServiceApplication $appSubSvc

4. Create Self-sign Certificate using Power shell  OR self sign Web hosting Certificate
1. New-SelfSignedCertificate -DnsName "www.xyz.com" -CertStoreLocation cert:\LocalMachine\My
2. https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/create-high-trust-sharepoint-add-ins    --> To create a self-signed test .pfx certificate file

5. Export PFX and CER file form IIS --> Cerficates - save both file at one location.
PFX will use in MVC Web config
CER file will  use in Sharepoint as New-SPTrustedSecurityTokenIssuer (regestrer through powershell command )

6. Register in Sharepoint through Powershell

$certloc = "C:\CERT\certificate.cer"
$certName = "HightTrustDemo"
$issuerId = '11111111-1111-1111-1111-111111111111' # MUST BE UNIQUE
$displayName = "High Trust Demo" # MUST BE UNIQUE

$certificate = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($certloc)
New-SPTrustedRootAuthority -Name $certName -Certificate $certificate

$realm = Get-SPAuthenticationRealm
$fullIssuerId = $issuerId + "@" + $realm
New-SPTrustedSecurityTokenIssuer -Name $displayName -Certificate $certificate -RegisteredIssuerName $fullIssuerId –IsTrustBroker

7. Add PFX file path , Password and ISsue ID inot MVC Web.config.

8. Generate Client ID and Cliet Secreate from Sharepoint site
URL: http:// SharePoint_website/_layouts/15/appregnew.aspx
Cliet ID : Auto
Secreate : Auto
app Name  : Any thing
Domain : www.xyz.com
Redirect URL : https://www.xyz.com:8443/

Add Cliet ID and Client Secreate  inot MVC Web.config.

Note: Here Www.xyz.com Domain, you can add into Host file (Start Menu -> Run -> "Drivers" -> etc/Host --> open wiht notepad)

9. Host your MVC Application into IIS 
1.IIS --> sites --> Create Web site - > set path and host header www.xyz.com and port 8443.
2. Change App pool identity to your admin user.

10. in visual Sudio Package app wiht client id and URL https://www.xyz.com:8443/

11. Upload *.app file into App catalog.

1. Sharepoint and MVC application Hostheader should not be same.

Friday, December 1, 2017

Disable O365 Sharepoint Online Enable Classic View only

Connect-SPOService –Url https://bajajelect-admin.sharepoint.com –Credential "Admin@xyz.onmicrosoft.com"
Import-Module Microsoft.Online.Sharepoint.PowerShell

$webUrl = ''
$username = "Admin@xyz.onmicrosoft.com"
$password = Read-Host -Prompt "Password for $username" -AsSecureString

[Microsoft.SharePoint.Client.ClientContext]$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl)
$clientContext.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)

# To apply the script to the site collection level, uncomment the next two lines.
$site = $clientContext.Site;
$featureguid = new-object System.Guid "E3540C7D-6BEA-403C-A224-1A12EAFEE4C4"

$site.Features.Add($featureguid, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None);


Thursday, August 31, 2017

Test Send Mail Power Shell Script

Write-Host "Sending Email"
$smtpServer = ""
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = "test1@abc.co.in"
$msg.ReplyTo = "test1@abc.co.in"
$msg.subject = "My Subject"
$msg.body = "This is the email Body."

Friday, July 21, 2017

New SP Trusted Identity Token Issuer

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
#Realm we created in Azure
$realm = "http:///_trust" #your sharepoint application url
#Replace "crescent.accesscontrol.windows.net" and "extranet.crescent.com" with yours here!
$signinurl = "https://claimprovider.com/account/loginv2"

$certloc = "E:\SSO\certificate.cer"
# see the attached file srv186CA.cer
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($certloc)
New-SPTrustedRootAuthority "DEV Trusted Authority" -Certificate $cert

$NameIdentifier = New-SPClaimTypeMapping -IncomingClaimType "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn" -IncomingClaimTypeDisplayName "UPN" -LocalClaimType "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn"
$GivenName = New-SPClaimTypeMapping -IncomingClaimType "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname" -IncomingClaimTypeDisplayName "Display Name" –LocalClaimType "http://schemas.microsoft.com/ws/2008/06/identity/claims/givenname"
$Email = New-SPClaimTypeMapping -IncomingClaimType "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" -IncomingClaimTypeDisplayName "Email" -SameAsIncoming

New-SPTrustedIdentityTokenIssuer -Name "SSO DEV" -Description "TOKEN ISSUER NAME" -realm $realm -ImportTrustCertificate $cert -ClaimsMappings $NameIdentifier,$GivenName,$Email -SignInUrl $signInURL -IdentifierClaim $NameIdentifier.InputClaimType

Thursday, July 20, 2017

Permanently Delete a SharePoint Site Collection.

#To begin, you will need to load the SharePoint Online module to be able to run commands in PowerShell. use your SharePoint administrative site.
Import-Module Microsoft.Online.Sharepoint.PowerShell
$credential = Get-credential
Connect-SPOService -url "" -Credential $credential

Remove-SPOSite -Identity -NoWait

#This command will pause the script for 20 seconds before proceeding.
Start-Sleep -s 20

#This script will permanently delete the SharePoint site collection after it is sent to the SharePoint Site Recycle Bin. You must replace the url  with your Sharepoint Online URL and use your Site Collection Name that is to be permanently deleted for this script to work properly.
Remove-SPODeletedSite -Identity ""
Delete Last x days Sharepoint List item 

Add-PSSnapin Microsoft.SharePoint.PowerShell

$web = Get-SPWeb ""
$list = $web.Lists["EmailNotification"]
$DeleteBeforeDate = [Microsoft.SharePoint.Utilities.SPUtility]::CreateISO8601DateTimeFromSystemDateTime([DateTime]::Now.AddDays(-7))
$caml=' {0} 1 ' -f $DeleteBeforeDate
$query=new-object Microsoft.SharePoint.SPQuery
$col | % {
Write-Host "Deleted ID " $_.Id
Write-Host " Total Item  Deleted" +$col.Count


Wednesday, July 19, 2017

Create Self sign Certificate Powershell Command

New-SelfSignedCertificate -DnsName "mydomain.com" -CertStoreLocation cert:\LocalMachine\My
ShareClear RecycleBin Using Powershell

Add-PSSnapIn Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue;
$sitecollectionUrl = ""
$siteCollection = New-Object Microsoft.SharePoint.SPSite($sitecollectionUrl)
write-host("Items to be deleted : " +$siteCollection.RecycleBin.Count.toString())
$now = Get-Date
write-host("Deleting started at " +$now.toString())
$now = Get-Date
write-host("Deleting completed at " +$now.toString())

BCS RevertToSelf Powershell

$bdc = Get-SPServiceApplication | where {$_ -match “Business Data Connectivity Service”};
$bdc.RevertToSelfAllowed = $true;