Timer Job History for a Specific Timer Job


First find the timer job you want.
Get-SPTimerJob | Select Name,Id
Get-SPTimerJob | ? Name -eq "job-workflow"
Get-SPTimerJob | ? Name -Like "*workflow*"

Then Filter it out using the Below Query
Add-PSSnapin Microsoft.SharePoint.PowerShell –erroraction SilentlyContinue [DateTime]$StartTime = "7/17/2015 00:00 am" [DateTime]$EndTime = "7/17/2015 11:59 pm" $Jobs = Get-SPTimerJob | ? name -eq "job-workflow" | % { $_.HistoryEntries } | Where-Object {($_.StartTime –gt $StartTime) -and ($_.EndTime -lt $EndTime) } $Jobs | Out-GridView
Use Gridview filters for additional filters.

Export all SharePoint Profiles to CSV – PowerShell


Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

$CSV = "C:\UserProfiles.csv"

$contextSiteUrl = "https://mysites.contoso.com/"
$serviceContext = Get-SPServiceContext -Site $contextSiteUrl
$UPMGR = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext);
$AllUserProfile= $UPMGR.GetEnumerator()

$Properties = @( 
            "SID", "ADGuid", "AccountName","FirstName","LastName","PreferredName","CountryCode","PersonalUrl","WorkPhone","Office","Department","Title","Manager","AboutMe","UserName","SPS-Skills","SPS-School","SPS-Dotted-line",
            "SPS-Peers","SPS-Responsibility","SPS-PastProjects","SPS-Interests","SPS-SipAddress","SPS-HireDate","SPS-Location","SPS-TimeZone","SPS-StatusNotes","Assistant","WorkEmail","SPS-ClaimID","SPS-ClaimProviderID","SPS-ClaimProviderType",
            "CellPhone","Fax","HomePhone","PictureURL"
           )

$Profilecollection = @()

foreach ($aProfile in $AllUserProfile) {
   $UserProfile = "" | select $Properties
   foreach ($field in $Properties) {
     if($aProfile[$field].Property.IsMultivalued) {
        try{
            $UserProfile.$field = $aProfile[$field] -join "|" } catch {}
     } else {
        try{
            $UserProfile.$field = $aProfile[$field].Value } catch {}
     }
   }
   if($aProfile.PersonalSite -ne $null)
     {
        try{
        $UserProfile.PersonalUrl = $aProfile.PersonalSite.Url  
        } catch {}
     }
   $Profilecollection += $UserProfile
}

$Profilecollection | Export-Csv $outputFile -NoTypeInformation

Export SharePoint Solutions (WSPs)


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$dirName = "E:\Solutionbackup\"
Write-Host Exporting solutions to $dirName 
foreach ($solution in Get-SPSolution) 
{ 
    $id = $Solution.SolutionID 
    $title = $Solution.Name 
    $filename = $Solution.SolutionFile.Name
    Write-Host "Exporting ‘$title’ to …\$filename" -nonewline 
    try { 
        $solution.SolutionFile.SaveAs("$dirName\$filename") 
        Write-Host " – done" -foreground green 
    } 
    catch 
    { 
        Write-Host " – error : $_" -foreground red 
    } 
}

Create Site Columns, Content Type and Add to Library using PowerShell


A good script to have for testing.

Add-PSSnapIn "Microsoft.SharePoint.Powershell"
#Get the site collection and web object
$siteColl = Get-SPSite -Identity "https://portal.contoso.com"
function Create-SiteColumnText ($siteColl, $CustomColumn)
{
    $rootWeb = $siteColl.RootWeb
    #Assign fieldXMLString variable with field XML for site column
    $fieldXMLString = "<Field Type='Text' Name='$CustomColumn'
    Description='Indicate date of last and next meeting and names of current members.'
    DisplayName='$CustomColumn'
    StaticName='$CustomColumn'
    Group='Custom Columns'
    Hidden='FALSE'
    Required='FALSE'
    Sealed='FALSE'
    ShowInDisplayForm='TRUE'
    ShowInEditForm='TRUE'
    ShowInListSettings='TRUE'
    ShowInNewForm='TRUE'></Field>"
    #See field XML on console
    #write-host $fieldXMLString
    #Create site column from XML string
    $rootWeb.Fields.AddFieldAsXml($fieldXMLString) 
    Write-Host "Column Added"
}

function Create-SiteColumnChoice ($siteColl, $CustomColumn)
{
    $rootWeb = $siteColl.RootWeb
    #Assign fieldXMLString variable with field XML for site column
    $fieldXMLString = "<Field Type='Choice' 
    Name='$CustomColumn'
    Description='Choice.'
    Format='Dropdown'
    DisplayName='$CustomColumn'
    StaticName='$CustomColumn'
    Group='Custom Columns'
    Hidden='FALSE'
    Required='FALSE'
    Sealed='FALSE'
    ShowInDisplayForm='TRUE'
    ShowInEditForm='TRUE'
    ShowInListSettings='TRUE'
    ShowInNewForm='TRUE'>
    <Default>Specification</Default>
                <CHOICES>
                  <CHOICE>Specification</CHOICE>
                  <CHOICE>Development</CHOICE>
                  <CHOICE>Test</CHOICE>
                  <CHOICE>Documentation</CHOICE>
                </CHOICES>
    </Field>"
    #See field XML on console
    #write-host $fieldXMLString
    #Create site column from XML string
    $rootWeb.Fields.AddFieldAsXml($fieldXMLString) 
    Write-Host "Column Added"
}


Create-SiteColumnText -siteColl $siteColl -CustomColumn "MyCustomColumn1"
Create-SiteColumnText -siteColl $siteColl -CustomColumn "MyCustomColumn2"
Create-SiteColumnText -siteColl $siteColl -CustomColumn "MyCustomColumn3"
Create-SiteColumnChoice -siteColl $siteColl -CustomColumn "MyCustomColumn4"

$web = $siteColl.RootWeb
$ctypeName = "MyCustomContentType"
$ctypeParent = $web.availablecontenttypes["Document"]
$ctype = new-object Microsoft.SharePoint.SPContentType($ctypeParent, $web.contenttypes, $ctypeName)
$web.contenttypes.add($ctype)
$field = $web.fields.getfield("MyCustomColumn1")
$fieldLink = new-object Microsoft.SharePoint.SPFieldLink($field)
$ctype.fieldlinks.add($fieldLink)

$field = $web.fields.getfield("MyCustomColumn2")
$fieldLink = new-object Microsoft.SharePoint.SPFieldLink($field)
$ctype.fieldlinks.add($fieldLink)

$field = $web.fields.getfield("MyCustomColumn3")
$fieldLink = new-object Microsoft.SharePoint.SPFieldLink($field)
$ctype.fieldlinks.add($fieldLink)

$field = $web.fields.getfield("MyCustomColumn4")
$fieldLink = new-object Microsoft.SharePoint.SPFieldLink($field)
$ctype.fieldlinks.add($fieldLink)
$ctype.Update()

$Library =$Web.Lists["Documents"]
$Library.ContentTypesEnabled = $true

$Library.ContentTypes.Add($ctype);
$Library.Update()

Inventory SharePoint Sites – PowerShell


Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue

$SiteCollections = @()
$Data = Import-Csv -Path C:\Everything\SitesProfile.csv
if($Data)
{

    [string]$SiteUrls =""
    foreach($Site in $Data)
    {
         $SiteUrl = $Site.SiteUrl
         $sitecoll = New-Object Microsoft.SharePoint.SPSite($SiteUrl)   
         foreach ($web in $sitecoll.AllWebs) {
                    foreach ($list in $web.Lists) {
                        if ($list.Hidden) { continue }
                            $data = @{
                            "Site" = $sitecoll.Url
                            "Web" = $web.Url
                            "List" = $list.Title
                            "ItemCount" = $list.ItemCount
                            "LastModified" = $list.LastItemModifiedDate 
                            }
                            $List = New-Object PSObject -Property $data
                            $SiteCollections +=$List
                       
                            }
                    $web.Dispose();
                }
         $sitecoll.Dispose()
    }
}
#$SiteCollections | Out-GridView
#$SiteCollections | Export-Csv -NoTypeInformation -Path C:\Everything\Inventory.csv

Create Site Collection Inventory as CSV – PowerShell


Below listed PowerShell can get it done

Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue

$SiteCollections = @()
$Data = Import-Csv -Path E:\Tools\Everything\ErrorProfile.csv
if($Data)
{

    [string]$SiteUrls =""
    foreach($Site in $Data)
    {
         $SiteUrl = $Site.SiteUrl
         $sitecoll = New-Object Microsoft.SharePoint.SPSite($SiteUrl)   
         foreach ($web in $sitecoll.AllWebs) {
                    foreach ($list in $web.Lists) {
                        if ($list.Hidden) { continue }
                            $data = @{
                            "Site" = $sitecoll.Url
                            "Web" = $web.Url
                            "List" = $list.Title
                            "ItemCount" = $list.ItemCount
                            "LastModified" = $list.LastItemModifiedDate 
                            }
                            $List = New-Object PSObject -Property $data
                            $SiteCollections +=$List
                       
                            }
                    $web.Dispose();
                }
         $sitecoll.Dispose()
    }
}
$SiteCollections | Out-GridView
$SiteCollections | Export-Csv -NoTypeInformation -Path E:\Tools\Everything\Inventory.csv

Get Site Collection Size using PowerShell


Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
$Sites = (Get-SPContentDatabase Content_DB).Sites
$AllSites = @();
foreach($site in $Sites)
{
    $Site = Get-SPSite $site.Url
    $Size = $site.usage.storage
    $Size = $Size/1mb
    $ASite = New-Object PSObject
    Add-Member -input $ASite noteproperty 'Url' $Site.url
    Add-Member -input $ASite noteproperty 'Size' $Size
    $AllSites+=$ASite
    $site.Dispose()
}
$AllSites | Sort-Object descending  | Out-GridView