Thursday, May 11, 2017

Delete IISLogs

'== This is the VB script which will delete the IIS logs which are older than 60 days from each site folder and write log about number of files deleted==='

intDeletedCount = 0

'===Append log file ========= '
Const ForAppending = 8

'===Create Log File ========= '
Set ObjForLog = CreateObject("Scripting.FileSystemObject")
Set ObjLogFile = ObjForLog.OpenTextFile("G:\Scripts\IISLogsCleanUp\log.txt", ForAppending, True)


' ======== Delete IIS log files ======== '
sLogFolder = "C:\inetpub\logs\LogFiles"
DelDate = 60   'in days
Set objFSO = CreateObject("Scripting.FileSystemObject")
set colFolder = objFSO.GetFolder(sLogFolder)
For Each colSubfolder in colFolder.SubFolders
        Set objFolder = objFSO.GetFolder(colSubfolder.Path)
        Set colFiles = objFolder.Files
        For Each objFile in colFiles
                iFileAge = now-objFile.DateLastModified
                if iFileAge > (DelDate+1)  then
                        objFSO.deletefile objFile, True
intDeletedCount = intDeletedCount + 1
                end if
        Next
Next


' ====== Count number of deleted file ====== '
intDeletedCount = intDeletedCount + 1

'======= Write Log file ====================='
ObjLogFile.WriteLine (Now & " -- " & intDeletedCount-1 & " IISLog(s) deleted older than 60days.")
ObjLogFile.Close


Set ObjForLog = Nothing
Set ObjLogFile = Nothing
Set objFSO = Nothing
Set colFolder = Nothing
Set objFolder = Nothing
Set colFiles = Nothing

Sunday, April 9, 2017

Site Collection Report

Powershell to get al site collections name, url, ID, storage, SharePoint groups, all groups role, users from each group, users' email ID, primary owner, secondary owner, Created date, last modified date:

$rootSite = Get-SPSite http://test.sharepoint.com
$spWebApp = $rootSite.WebApplication

foreach($site in $spWebApp.Sites)
{
    foreach($sites in $site.RootWeb)
{

$web = $site.OpenWeb()
$groups = $web.sitegroups

foreach ($grp in $groups)
{
$groupName = $grp.name

$role = $grp.ROles




foreach ($user in $grp.users)
{
write-host $sites.title, "User " $user.UserLogin, "Group: " $groupName, $role  -foregroundcolor yellow

$sites.url + "$" + $sites.Title + "$" + $sites.ID + "$" + $Site.Usage.Storage + "$" + $groupName + "$" + $role + "$" + $user.UserLogin + "$" +  $user.Name + "$" +  $user.Email + "$" +  $Site.Owner.Name + "$" + $Site.Owner.Email + "$" + $Site.SecondaryContact.Name + "$" + $Site.SecondaryContact.Email + "$" + $sites.Created + "$" + $sites.lastitemmodifieddate  | out-file "E:\SiteCollectionreport.csv" -Append

}
}
}
$web.Dispose()
$site.Dispose()
}