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);

$clientContext.ExecuteQuery();

Thursday, August 31, 2017

Test Send Mail Power Shell Script

Write-Host "Sending Email"
$smtpServer = "192.168.1.246"
$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.To.Add("jatin@xyz.com")
$msg.subject = "My Subject"
$msg.body = "This is the email Body."
$smtp.Send($msg)

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

[System.reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$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
$query.Query=$caml
$col=$list.GetItems($query)
$col | % {
$list.GetItemById($_.Id).Delete()
Write-Host "Deleted ID " $_.Id
}
Write-Host " Total Item  Deleted" +$col.Count

$web.Dispose()

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())
$siteCollection.RecycleBin.DeleteAll();
$now = Get-Date
write-host("Deleting completed at " +$now.toString())
$siteCollection.Dispose();