Share via


Powershell Scripts - to Gather Inventory Data from Sharepoint Site collection

**Fetch Content Types:
**
$site = new-object Microsoft.SharePoint.SPSite([SiteName])
$cts = $site.rootweb.ContentTypes
echo "Processing..."
'"CT Name"' + `
',"CT ID"' + `
',"CT Description"' + `
',"CT Group"' | Out-File "C:\ListofAllCts.csv"
 ForEach ($id in $cts)
{
         
            '"' + $id.Name + `
            '","' + $id.Id + `
            '","' + $id.Description + `
            '","' + $id.Group + `
            
            '"' | Out-File "C:\ListofAllCts.csv" -append
          
      
   
}
 
$site.Dispose()
 
echo "Finished!"

Export Workflow of Site Collection in form of CSV

# All scripts running locally are allowed
Set-ExecutionPolicy RemoteSigned
#Load SharePoint Assemblies
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") >null

$siteurl="[Site URL]"
$site=new-object Microsoft.SharePoint.SPSite($siteurl)

#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 [Path]\Potalworkflows.csv
"Workflow Count " + $workflowcount >>[Path]\Portalworkflows.csv

$site.Dispose()