Saturday, October 5, 2019

List of Running Workflows in SharePoint Site Collection using PowerShell

Clear-Host
$site=Get-SPSite("http://2010.ajtech.com");

#Initialize Workflow Count variable
$workflowcount = 0

#Foreach loop to loop through all webs, and lists with workflow associations, and exclude workflows that have previous versions and write findings to .csv file.

function Get-Workflows()
{
foreach($web in $site.AllWebs)
{
foreach($list in $web.Lists)
{
foreach($wf in $list.WorkflowAssociations)
{
if ($wf.Name -notlike "*Previous Version*")
{
$hash = @{"[URL]"=$web.Url;"[List Name]"=$list.Title;"[Workflow]"=$wf.Name}
New-Object PSObject -Property $hash | Sort-Object

}
}
}
}
}

foreach($web in $site.AllWebs)
{
foreach($list in $web.Lists)
{
foreach($wf in $list.WorkflowAssociations)
{
if ($wf.Name -notlike "*Previous Version*")
{
$workflowcount += 1
}
}
}
}

Get-Workflows | Export-csv c:\workflows.csv
"Workflow Count " + $workflowcount >> c:\workflows.csv

$site.Dispose()

Get List of Video Files in SharePoint using PowerShell

cls
function Get-DocInventory($Url) {
    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
    $farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
       $site = new-object Microsoft.SharePoint.SPSite $Url

                 foreach ($web in $site.AllWebs) {
                    foreach ($list in $web.Lists) {
                        if ($list.BaseType -ne "DocumentLibrary") {
                            continue
                        }
                        foreach ($item in $list.Items) {

                        #Write-Host $item.name.ToString().ToLower()
                        if ($item.name.ToString().ToLower().Endswith(".mp4") -or $item.name.ToString().ToLower().Endswith(".avi") -or $item.name.ToString().ToLower().Endswith(".wmv") -or $item.name.ToString().ToLower().Endswith(".mov") -or $item.name.ToString().ToLower().Endswith(".flv")){
                            $data = @{

                                #"Web Application" = $webApp.ToString()
                               # "Site" = $site.Url
                                "Web" = $web.Url
                                "list" = $list.Title
                                "Item ID" = $item.ID
                                "Item URL" = $item.Url
                                "Item Title" = $item.Title
                                "Item Created" = $item["Created"]
                                "Item Modified" = $item["Modified"]
"Item Modified By" = $item['Editor']
                                "File Size" = $item.File.Length/1KB
                            }
                            New-Object PSObject -Property $data
                            Write-Host $item.name.ToString()
                            }
                        }
                    }
                    #$web.Dispose();
               
    }
  }

lists enabled with incoming email settings in SharePoint using PowerShell

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$SPWebApp = Get-SPWebApplication "http://2010.ajtech.com"


#create a CSV file
"E-Mail,List,Site" > "EMail-Enabled_home.csv" #Write the Headers in to a text file
 
foreach ($SPsite in $SPwebApp.Sites)  # get the collection of site collections
{
    foreach($SPweb in $SPsite.AllWebs)  # get the collection of sub sites
        {
            foreach ($SPList in $SPweb.Lists)
                {
                    if ( ($splist.CanReceiveEmail) -and ($SPlist.EmailAlias) )
                        {
                            # WRITE-HOST "E-Mail -" $SPList.EmailAlias "is configured for the list "$SPlist.Title "in "$SPweb.Url
                           $SPlist.Title +" ;" + $SPweb.Url >> EMail-Enabled_home.csv  #append the data
                        }
                }
        }
}

List of Checkout files in SharePoint using PowerShell

function GetCheckedOutFiles($web)
{
Write-Host "Processing Web: $($web.Url)..."
        foreach ($list in ($web.Lists | ? {$_ -is [Microsoft.SharePoint.SPDocumentLibrary]})) {
            Write-Host "`tProcessing List: $($list.RootFolder.ServerRelativeUrl)..."
            foreach ($item in $list.CheckedOutFiles) {
                if (!$item.Url.EndsWith(".aspx")) { continue }
                $hash = @{
                    "URL"=$web.Site.MakeFullUrl("$($web.ServerRelativeUrl.TrimEnd('/'))/$($item.Url)");
                    "CheckedOutBy"=$item.CheckedOutBy;
                    "CheckedOutByEmail"=$item.CheckedOutByEmail
                }
                New-Object PSObject -Property $hash
            }
            foreach ($item in $list.Items) {
                if ($item.File.CheckOutStatus -ne "None") {
                    if (($list.CheckedOutFiles | where {$_.ListItemId -eq $item.ID}) -ne $null) { continue }
                    $hash = @{
                        "URL"=$web.Site.MakeFullUrl("$($web.ServerRelativeUrl.TrimEnd('/'))/$($item.Url)");
                        "CheckedOutBy"=$item.File.CheckedOutByUser;
                        "CheckedOutByEmail"=$item.File.CheckedOutByUser.Email
                    }
                    New-Object PSObject -Property $hash
                }
            }
        }
foreach($subWeb in $web.Webs)
{
GetCheckedOutFiles($subweb)
}
        $web.Dispose()
}

$web = get-spweb $args[0]

GetCheckedOutFiles($web)

List of Unused Sites in SharePoint using PowerShell

$outputPath = “C:\unread\UnusedSites.doc”

$lastDate=Read-Host “Last Accessed Date (in format mm/dd/yyyy)”

$gc = Start-SPAssignment

$site=$gc | get-spsite -Identity http://2010.ajtech.com



foreach($web in $site.AllWebs)
{

$siteusage = $site.Usage.Storage/1MB

$Hits = $site.Usage.Hits

$Created = [datetime]$web.Created



if ($web.LastItemModifiedDate -lt $lastDate)

{
Write-Host -f Red “Site is old…” + $Web.Title +"Site Usage is ..." $siteusage + "Created Date is ..." $Created

Add-Content -Path $outputPath -Value “$($web.url),
$($web.LastItemModifiedDate),$($web.Author)”

}

else
{
Write-Host -f Green “Site: [" + $web.Title + "] Last Modified Date: ” + $web.LastItemModifiedDate + $web.url + $siteusage + $Created

Add-Content -Path $outputPath –Value “$($web.url),
$($web.LastItemModifiedDate),$($web.Author)”
}
}



Stop-SPAssignment $gc

Last modified date of List/Library in SharePoint using PowerShell

Add-PSSnapin Microsoft.Sharepoint.Powershell
[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges({
$Output="C:\users\ajtech\desktop\Output.csv";
$webApplicationURL = "http://2010.ajtech.com/"
$webApp = Get-SPWebApplication $webApplicationURL

if($webApp -ne $null)
{
  Write-Host "Web Application : " + $webApp.Name ;

  foreach($siteColl in $webApp.Sites)
    {
     if($siteColl -ne $null)
      {
         Write-Host "Site Collection : " + $siteColl.Url ;
         foreach($subWeb in $siteColl.AllWebs)
          {
            if($subWeb -ne $null)
              {
                #Print each Subsite;
                Write-Host $subWeb.Url ;
                 Write-Host $subWeb ;
$list = $subweb.Lists
write-Host " List last modified date is .. " + $list.LastModifiedDate + " And Modified By " + $List.Author
                 $subWeb.Dispose()
              }
           else
              {
                Echo $subWeb "does not exist"
              }
          }
            $siteColl.Dispose()
       }
     else
         {
            Echo $siteColl "does not exist"
         }
     }
} else
     {       Echo $webApplicationURL "does not exist, check the WebApplication name"
     }Remove-PsSnapin Microsoft.SharePoint.PowerShell
Echo Finish
}); 

There is no data available for this report. Here are some possible reasons: (1) Web Analytics has not been enabled long enough to generate data; (2) There is insufficient data to generate this report; (3) Data logging required for this report might not be enabled; (4) Data aggregation might not be enabled at the level required for this report


There is no data available for this report. Here are some possible reasons: (1) Web Analytics has not been enabled long enough to generate data; (2) There is insufficient data to generate this report; (3) Data logging required for this report might not be enabled; (4) Data aggregation might not be enabled at the level required for this report.

Event 2137 SharePoint Foundation

The SharePoint Health Analyzer detected an error.  Product / patch installation or server upgrade required.
All required products must be installed on all servers in the farm, and all products should have the same patching and upgrade level across the farm.

Resolution



This resolution is only applicable if you are experiencing the events described in the Symptoms section. There are several alerts that can be generated by these health checks, you should check the event description and the link provided with the event before proceeding. Most alerts are discussed here: http://technet.microsoft.com/en-us/library/ff686788.aspx
In order to update the SharePoint databases, you must manually run the PSconfig utility. To run the utility:

1. Open an Administrative command prompt. 
2. Change directory to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN 
3. Run PSConfig.exe -cmd upgrade -inplace b2b -force -cmd applicationcontent -install -cmd installfeatures

Sometimes one w3wp process will take more cpu utilization and wa can’t access that site


Sometimes one w3wp process will take more cpu utilization and wa can’t access that site.
That time just get the info of all process running on it and get their utilization by looking inti task manager. Select processes from all users in the left corner. Now it will listout which w3wp is taking high utilization. Now we need to find out that w3wp is related to which app pool and need to recycle that app pool in IIS.

By using that find which app pool is related to which w3wp.exe

Go to c: windows/system32/inetsrv/ .\appcmd list wp

This will list out app pools with PID in processes

Find out high usage app pool and recycle it in IIS.

Issue was solved.

Items are being deleted from the index and are not retrievable from the main default.aspx page search bar


Issue Definition:
-------------------------
1)      Users are unable to retrieve items from the index they could previously.
2)      Items are being deleted from the index and are not retrievable from the main default.aspx page search bar.
RESOLUTION:
-----------------------------------------------------
As part of troubleshooting, I did following steps.

1)      We run psconfig.exe on application server.
2)      Need to check Disable loopback check is setup or not on server. Went to registry and found that it is already there.
3)      Specify host names: To specify the host names that are mapped to the loopback address and can connect to Web sites. This method would be preferred for NTLM authentications.

· Click Start, click Run, type regedit, and then click OK.
· In Registry Editor, locate and then click the following registry key:
· HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0
· Right-click MSV1_0, point to New, and then click Multi-String Value.
· Type BackConnectionHostNames, and then press ENTER.
· Right-click BackConnectionHostNames, and then click Modify.
· In the Value data box, type the host name or the host names for the sites that are on the local computer, and then click OK.
· Quit Registry Editor, and then restart the IISAdmin Service

In the above step, I specified all host names and tried to start crawling. No use.

2)            In technet blog, I found that if any patches effected on SharePoint services, we need to recreate and enter value for disablleloopback check in registry entry.

3)            Mentioned admin account for Search Service application administrators in central admin.

4)            Administrators for user profiles service application:  Here we will mention users who will be able to manage settings related to UPS and search content. Checked admin account rights for UPS and found admin account is not having Retrieve people data for search crawlers. Checked that permissions for admin account.

Permanently Delete a SharePoint Site Collection

#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. You must also replace the url "https://anjantech-admin.sharepoint.com" and use your SharePoint administrative site.

Import-Module Microsoft.Online.Sharepoint.PowerShell

$credential = Get-credential
Connect-SPOService -url https://anjantech-admin.sharepoint.com -Credential $credential

#This command will delete the SharePoint site collection. You must replace the url "https://anjantech.sharepoint.com/sites/SiteCollectionName" with your Sharepoint Online URL and use the Site Collection Name that is to be deleted for this script to work properly.

Remove-SPOSite -Identity https://anjantech.sharepoint.com/sites/SiteCollectionName -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 “https://anjantech.sharepoint.com/sites/SiteCollectionName” 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 https://anjantech.sharepoint.com/sites/SiteCollectionName

Delete Site Collection with Sub Sites

#Deleting a SharePoint Site Collection and its Subsites

#To begin, you will need to load the SharePoint Online module to be able to run commands in PowerShell. You must also replace the url "https://anjantech-admin.sharepoint.com" and use your SharePoint administrative site.

Import-Module Microsoft.Online.Sharepoint.PowerShell
$credential = Get-credential
Connect-SPOService -url https://anjantech-admin.sharepoint.com -Credential $credential

#This command will delete the SharePoint site collection. You must replace the url "https://anjantech.sharepoint.com/sites/SiteCollectionName" with your Sharepoint Online URL and use the Site Collection Name that is to be deleted for this script to work properly.

Remove-SPOSite -Identity https://anjantech.sharepoint.com/sites/SiteCollectionName -NoWait

Connect with SharePoint Online using SP Online Management Shell

Install the SharePoint Online Management Shell by downloading and running the https://www.microsoft.com/en-us/download/details.aspx?id=35588 or installing module from the PowerShell Gallery   https://www.powershellgallery.com/packages/Microsoft.Online.SharePoint.PowerShell/16.0.19223.12000



If your operating system is using PowerShell 5 or newer, you can install Sharepoint Online Management Shell also by running following command in administrative mode.

Install-Module -Name Microsoft.Online.SharePoint.PowerShell

To open the SharePoint Online Management Shell command prompt, from the Start screen, type sharepoint, and then click SharePoint Online Management Shell.



To connect with a user name and password



Fill in the values for the $adminUPN and $orgName variables (replacing all the text between the quotes, including the < and > characters), and then run the following commands at the SharePoint Online Management Shell command prompt:


$adminUPN="<the full email address of a SharePoint administrator account, example: anjan@anjantech.com>" $orgName="<name of your Office 365 organization, example: anjantech>" $userCredential = Get-Credential -UserName $adminUPN -Message "Type the password." Connect-SPOService -Url https://$anjantech-admin.sharepoint.com -Credential $userCredential

The site requires that the feature {.......} to be activated in site collection.





Get-spfeature –identity ca7bd552-10b1-4563-85b9-5ed1d39c962a –url "http://site collection url " –force

It will activate the feature of that particular GUID
Then need to enable ctypes feature also

Enable-spfeature –identity ctypes –url "http://site collection url " -force