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
No comments:
Post a Comment