Thursday, July 1, 2021

Script for Deleting Items

 cls

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$WebUrl = "http://yoursite"

###$Libraries = "Library1","Lib2","Lib3" ##UNCOMMENT AND COMMENT LINE 8

$Libraries = Get-Content -Path D:\libraries.txt

try

{

$reply = Read-Host -Prompt "Do you want to delete files/items?[y/n]"


Foreach ($library in $Libraries) 

{

#Get web List and List Items

$Web = Get-SPWeb $WebUrl

$List = $Web.Lists[$library]

$ListItems = $List.items

Write-host "Total Items in the List:"$List.ItemCount

 

#Iterate through each item in the list

foreach ($Item in $ListItems)

{

Write-host "Deleting from List/Library: $($library)"

"List/Library: $($library) & Item Details $($item)" | Out-File -FilePath D:\DeletedItems.txt -Append

if ($reply -match "[yY]") 

    $List.GetItemByID($Item.id).Delete()

    Write-host "Deleted Item: $($item.id)" -foregroundcolor Red

"Deleting from List/Library: $($library) & Item Details $($item)" | Out-File -FilePath D:\DeletedItems.txt -Append

}

}

}

}

catch

{

Write-Output "Error Occured while performing action"

"Error Occured while deleting from library: $($library) & Item Details $($item) with exception $($_.Exception.Message)" | Out-File -FilePath D:\DeletedItems.txt -Append

}

######################################################################

Import-Module WebAdministration



function SendMail

{

[cmdletbinding()]

Param (

[String]$SendTo,[String]$Appname,[String]$Status


write-host "Email Operation"

#Mail Variables

$EmailSubject = "App Pool Status"

$mailmessage = New-Object system.net.mail.mailmessage

$body = "Hello This is Email Regarding "

Send-MailMessage -From $EmailFrom -To $SendTo -Subject $EmailSubject -Body $body -BodyAsHtml -SmtpServer $smtpServer -Cc 'Team@gmail.com'

}





############# Email Variables Region Start#########################

$EmailFrom ='XYZ <do_not_reply@.XYZ.com>'

$smtpServer = "smtp.XYZ.com" 

$cc ='discolleeration@ZYX.com'


$anonAuthFilter =    "/system.WebServer/security/authentication/AnonymousAuthentication"

$windowsAuthFilter = "/system.WebServer/security/authentication/windowsAuthentication"


$value = 'false'

$AppName = "DefaultAppPool"


$anonAuth = Get-WebConfigurationProperty -filter $anonAuthFilter -name Enabled -location $AppName

Write-Host  $anonAuth.Value



$winAuth = Get-WebConfigurationProperty -filter $windowsAuthFilter -name Enabled -location $AppName

Write-Host  $winAuth.Value


################################

SendMail -SendTo "EMAILID@GMAIL.COM" -APPName $AppName -Status $anonAuth.Value


Sunday, February 26, 2017

Simple o365 get lists of sites & subsites with title available


Add-Type –Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type –Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

$AdminUrl = "https://kmdcloud-admin.sharepoint.com/"
$UserName = "kmd@kmdloud.onmicrosoft.com"
$Password = "pwd"
$SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $SecurePassword
$SPOCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)





function Get-SPOWebs(){
param(
   $Url = $(throw "Please provide a Site Collection Url"),
   $Credential = $(throw "Please provide a Credentials")
)
 
  $context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
  $context.Credentials = $Credential
  $web = $context.Web
  $context.Load($web)
  $context.Load($web.Webs)
  $context.ExecuteQuery()
  foreach($web in $web.Webs)
  {
       Get-SPOWebs -Url $web.Url -Credential $Credential
       $web
  }
}






#Retrieve all site collection infos
Connect-SPOService -Url $AdminUrl -Credential $Credentials
$sites = Get-SPOSite

#Retrieve and print all sites
foreach ($site in $sites)
{
    Write-Host 'Site collection:' $site.Url    
    $AllWebs = Get-SPOWebs -Url $site.Url -Credential $SPOCredentials
    $AllWebs | %{ Write-Host $_.Title }  
    Write-Host '-----------------------------'
}




$AllWebs = Get-SPOWebs -Url 'https://kmddoulacloud.sharepoint.com' -Credential $SPOCredentials
$AllWebs | %{ Write-Host $_.Title }

Monday, April 18, 2016

Add Site Collection Admins

cls
 Add-PsSnapin Microsoft.SharePoint.PowerShell

$webApplicationURL = "webapplication URL"
 $group="Domain\GroupName"

$webApp = Get-SPWebApplication $webApplicationURL

if($webApp -ne $null)
 {
 "Web Application : " + $webApp.Name# | Out-File $out -Append

foreach($siteColl in $webApp.Sites)
{ Write-host "Site Collection : " + $siteColl.Url

Write-host $siteColl $site = Get-SPWeb $siteColl.Url $check=$site.EnsureUser($group) | Select $_.UserLogin write-host $check Write-Host " Now adding Domain\GroupName to site collection administrators..." -BackgroundColor DarkGray New-SPUser -UserAlias $check -DisplayName $group -Web $site $User = Get-SPUser -Web $site -Identity $check $user.IsSiteAdmin = $true $user.Update() Write-Host " Added" -ForegroundColor Green
}
}

Remove-PsSnapin Microsoft.SharePoint.PowerShell

Echo Finish

Tuesday, March 22, 2016

Powershell to Get Users From AD Group

Get-ADGroupMember -identity "GROUPNAME" -Recursive | Get-ADUser -Property DisplayName | Select Name,ObjectClass,DisplayName

Thursday, September 17, 2015

How to Enable or Disable Document Property Promotion (ParserEnabled) in SharePoint 2013

How to Enable or Disable Document Property Promotion (ParserEnabled) in SharePoint 2013

This is the way to solve issues on uploading document into SharePoint 2013 Document Library. After upload the document into SharePoint library, the document had the metadata (document properties) of the original document. Metadata that is changed on the document will revert to the original values that were given to the document; this occurs both from SharePoint and from MS Word.
 
Solution 1 – Remove Document Properties & personal Information using Inspect
1.      Open file using Microsoft office
2.      Click file and the inspect document (check for issues)
3.      Tick only on document properties & personal information
4.      Inspect & then remove
5.      Then Save
6.      Upload document into SharePoint.
 
Solution 2 – Disable Document Property Promotion using PowerShell
The SPWeb object has a ParserEnabled property, which enables or disables this functionality.  Using the PowerShell script, we can turn off this functionality at the web level. Sample script to disable the document parser feature in SharePoint:
1.      Open the SharePoint 2013 Management Shell as Administrator.
2.      Run the following script to disable document property promotion.
 
C:\> $web
        Url
        ---
        http://spfe01/sites/SITENAME/SUBSITENAME
C:\> $web.parserenabled
        True
C:\> $web.parserenabled  = $false
C:\> $web.Update()
C:\> $web.parserenabled
        false
 
 
3.      Document Property Promotion is disabled successfully and when you try to upload a document you will find that all the fields are empty
 
Reference 3:http://fairulshahrizat.blogspot.in/2014/10/how-to-enable-or-disable-document.html

Friday, September 4, 2015

Thursday, September 3, 2015

Get all Columns of List (including Hidden) using powershell

Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null

$url = "SiteUrl/"
$listName = "Listname"
$path ="C:\Temp\Columns.csv"

$web = Get-SPWeb $url
$list = $web.Lists.TryGetList($listName)
$list.ContentTypes | % { $_.FieldLinks } | select Name |  Export-Csv -path $path