Powershell script for SharePoint 2010 & SharePoint 2007 Site Usage report

SharePoint 2010 & SharePoint 2007  – Powershell script for finding site Url, Title,user Count, Primary & Secondary Site collection admins, Usage, Hits, views, Created Date, last modifed date

[System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
# get local farm
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
# get web services from local farm
$websrvcs = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]}
# format for .csv file output
$outputToCSV = @()
function CheckedOutItems()
{
    # get all web services available in the farm   
    foreach ($websrvc in $websrvcs) {
        # retrieve web applications
        foreach ($webApp in $websrvc.WebApplications) {
            # now get site collections from the web application
            foreach ($site in $webApp.Sites) {
                # process each web site
                Try {
                    foreach ($web in $site.AllWebs) {
                         $siteUrl = $web.Url
                         $siteName = $web.Title
                         $siteUserCnt = $web.AllUsers.Count
                         $PimarySiteAdmin = $site.Owner.Name
                         $SecondarySiteAdmin = $site.SecondaryContact.Name
                      $siteusage = $site.Usage.Storage/1MB
                         $Hits = $site.Usage.Hits                       
                         $Created = [datetime]$web.Created
                         $LastModified = $Web.LastItemModifiedDate
                         $SnapShot = (get-date)
                         $LastUpdate = ($SnapShot – [datetime]$LastModified)

                         $outputToCSV += New-Object PSObject -Property @{"Site Title" = $siteName; "Url" = $siteUrl; "Primary site collection admin"= $PimarySiteAdmin; 
                                                                        "Secondary site collection admin"=$SecondarySiteAdmin; "Total Users" =$siteUserCnt;"Size" = $siteusage; 
                                                                        "Date Last Modified" = $LastModified; "Days Last Update" = $LastUpdate; "Hits" =$Hits; "Date Created" =$Created
                                                                        }
                                        $file_date = get-date -format M-d-yyyy
                                        $file_name = "$env:USERPROFILE\Desktop\NoCheckedInVersion"+ $file_date + ".csv"
                                        $outputToCSV | ConvertTo-Csv -notype > $file_name

                } # end $site.AllWebs loop
            } # end Try statement 
            # General catch exceptions
            Catch {
                    "General Exceptions caught: " >> "$env:USERPROFILE\Desktop\errorlog.txt"
                    $_.Exception.Message >> "$env:USERPROFILE\Desktop\errorlog.txt"
            }# end general catch statement
            }
        }
    }
}
# Make a call to the function
CheckedOutItems
Advertisements

SharePoint 2010 – PowerGUI and the PowerGUI Extension for Visual Studio 2010

SharePoint 2010 – PowerGUI and the PowerGUI Extension for Visual Studio 2010

SharePoint 2010 -Error in InfoPath web browser form: “An error occurred querying a data source.”

SharePoint 2010 -Error in InfoPath web browser form: “An error occurred querying a data source.”

On the Web Application are some browser enabled InfoPath forms. Some of them consume a SharePoint Web Service to query user information. After switching the Web App to HTTPS there was an Error while loading the form in browser.

First error message: “An error occurred querying a data source.”

Second error message: “You do not have permissions to access a Web service that provides data required for this form to function correctly.”

Cause: we are using SSL certificates for SharePoint 2010 web applications and we need to import the certificate into SharePoint trusted root certify ate store in order to InfoPath service to work.

$cert = Get-childItem "cert:\LocalMachine\CA\9A68CD6434D370CA40AA6CF443D86B46D2D3B485"
new-SPTrustedRootAuthority -Certificate $cert -Name "Sempra Energy Utilities Root Authority"

One last note – the ‘Get-childItem’ cmdlet can be used to walk the cert store as follows:
Get-childitem “cert:\*”
Get-childitem “cert:\LocalMachine\ *”
Get-childitem “cert:\LocalMachine\CA\*”
Resource: http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010general/thread/55471ccb-3efe-48e0-b6e7-007f64bbac04
http://ikarstein.wordpress.com/2011/07/01/869/
http://practicalsharepoint.blogspot.com/2012/06/info-path-forms-using-sharepoint-web.html

SharePoint 2010 – Powershell Script to Automatically deploy WSP packages

SharePoint 2010 –  Powershell Script to Automatically deploy WSP packages

packages = (dir *.wsp | Select-Object name)  
$currentDir = (Get-Location).Path  
Add-PSSnapin Microsoft.Sharepoint.PowerShell -ErrorAction "SilentlyContinue"
Start-SPAssignment -Global    # This cmdlet takes care of the disposable objects to prevent memory leak. 
Write-Host "Started package installation"
function WaitForJobToFinish ([string]$solutionName)    
{
     $JobName = "solution-deployment-$solutionName*"    
     $job = Get-SPTimerJob | ?{ $_.Name -like $JobName }    
 if ($job -eq $null)     
 {
         Write-Host "Timer job not found"
 }else
 {
  $JobFullName = $job.Name        
  Write-Host -NoNewLine "Waiting to finish job $JobFullName"            
  while ((Get-SPTimerJob $JobFullName) -ne $null)         
  {
   Write-Host -NoNewLine .
          Start-Sleep -Seconds 2        
  }
  Write-Host  "Finished waiting for job.."    
 }
foreach ($i in $packages)  
{  
    Write-Host -NoNewLine "Waiting for deployment jobs to finish..."            
    while ((Get-SPTimerJob  | ?{$_.Name -like "solution-deployment*"}) -ne $null)         
    {
     Write-Host -NoNewLine .
     Start-Sleep -Seconds 2        
    }
    Write-Host  "Finished waiting for job.."    
    Write-Host "Retracting: " + $i  
    $solution = (Get-SPSolution | where-object {$_.Name -eq $i.Name})  
    Write-Host $solution.Name  
    if ($solution -ne $null)  
    {  
      Write-Host "Solution Found..." 
     if ($solution.Deployed -eq $true)  
     {  
      Write-Host "Uninstalling..."
      try
      {
       Uninstall-SPSolution -Identity $i.Name -AllWebApplications -Confirm:$false
      }catch
      {
       Uninstall-SPSolution -Identity $i.Name -Confirm:$false  
      }
     }
     Write-Host "Retract Completed!" 
     Write-Host "Removing Solution..." 
     do{
  Write-Host -NoNewLine .
             Start-Sleep -Seconds 2
     }
     until ($solution.Deployed -eq $false)
     WaitForJobToFinish $i.Name
            Start-Sleep -Seconds 5
     Remove-SPSolution -Identity $i.Name -Force -Confirm:$false 
     Write-Host "Remove Completed!" 
    }  
    else 
    {  
     Write-Host "WSP Package was not previously installed, moving to next step" 
    }  
}  
foreach ($i in $packages) 
{  
    Write-Host "Deploying: " + $i  
    $solution = (Get-SPSolution | where-object {$_.Name -eq $i.Name})  
    if ($solution -eq $null)  
    {  
     Write-Host "Adding Solution..." 
     $solution = Add-SpSolution -LiteralPath ($currentDir + "\" + $i.Name)  
     WaitForJobToFinish $solution.Name
     Write-Host "Deployment Completed!" 
     Write-Host "Installing Solution..."
     try{
  Write-Host "Installing for web application(s)"
         Install-SPSolution -Identity $solution.Name -allwebapplications -GACDeployment -CASPolicies
      }
     catch 
     {
  Install-SPSolution -Identity $solution.Name -GACDeployment -CASPolicies
     }
    }  
}
}
Stop-SPAssignment -Global    # This cmdlet takes care of the disposable objects to prevent memory leak.
Remove-PsSnapin Microsoft.SharePoint.Powershell

Enabling Mime types using PowerShell Script

Enabling Mime types using PowerShell Script

[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | out-null  
$oContentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService;  
[Microsoft.SharePoint.Administration.SPWebApplicationCollection]$waColl = $oContentService.WebApplications;  
$waColl1 = $waColl | where-object {$_.IsAdministrationWebApplication -eq $FALSE}  
foreach ($wa in $waColl1)  
{  
                write-host "Web application " $wa.DisplayName
                $mimetype = "application/pdf"
                If ($wa.AllowedInlineDownloadedMimeTypes -notcontains $mimetype) 
                {
                                $wa.AllowedInlineDownloadedMimeTypes.Add($mimetype)
                                $wa.Update()
                                Write-Host -ForegroundColor Yellow "Added MIME type " $mimetype
                }
                Else
                {
                                Write-Host -ForegroundColor Green "MIME type " $mimetype " is already added."
                } 
                $mimetype = "application/vnd.ms-outlook"
                If ($wa.AllowedInlineDownloadedMimeTypes -notcontains $mimetype) 
                {
                                $wa.AllowedInlineDownloadedMimeTypes.Add($mimetype)
                                $wa.Update()
                                Write-Host -ForegroundColor Yellow "Added MIME type " $mimetype
                }
                Else
                {
                                Write-Host -ForegroundColor Green "MIME type " $mimetype " is already added."
                } 
}  
write-host "Finished."