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 "" and "" with yours here!
$signinurl = ""

$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 "" -IncomingClaimTypeDisplayName "UPN" -LocalClaimType ""
$GivenName = New-SPClaimTypeMapping -IncomingClaimType "" -IncomingClaimTypeDisplayName "Display Name" –LocalClaimType ""
$Email = New-SPClaimTypeMapping -IncomingClaimType "" -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 "" -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;