Showing posts with label Powershell with Sharepoint. Show all posts
Showing posts with label Powershell with Sharepoint. Show all posts

Tuesday, May 5, 2009

Does Operating System edition matters with powershell ?

Yes, it does matters when accessing Sharepoint Object Model through powershell.

Make sure that you use PowerShell 64 bit when you trying to manipulate the SharePoint object model from a script on a 64 bit OS machine.

If you try run a script that accesses the SharePoint object model in a 32 bit PowerShell window from a 64 bit OS, you will run into errors that are rather hard and confusing to diagnose: The error you will receieve will be as below which is totally misleading.

Error: “The Web application at http://servername could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.”At line:1 char:38+ $spsite=[Microsoft.SharePoint.SPSite]( <<<< “http://servername”)

I hope this post saves some time for someone in sharepoint world !

Wednesday, April 29, 2009

Site Collection Inventory with Powershell

In my recent project I was asked to get site collection inventory between various enviornments. Requirement was to get a automated file with certain information of each site. Information that was needed for each site is as below.

Name
Title
Description
Theme
WebTemplate
Author
Created
Modified
Sites
Users
ParentWeb
Url
ServerRelativeUrl
ID

Requirement seemed to be simple but there was no easy answer who what my soluton would be.
Initially when I started to think of a solution various few things that came to my mind including copy and paste through Content and Structure under sitecollection settings, wirting object model code and then it clicked with check what powershell has to offer.

Using power shell I wrote useful script to get all the required information for each site and exported it to a .csv file. Following is the script where $url should be replaced with the actual site collection.

$Path = $pwd.ToString() + "\SiteInformation.csv"
$SiteInfo = Get-SiteInformation $Url $SiteInfo Export-Csv $Path -NoTypeInformation

function Get-SiteInformation ([string]$Url) {
$SPSite = New-Object Microsoft.SharePoint.SPSite($Url) $AllWebs = $SPSite.AllWebs

$AllWebs ForEach {
if ($_.Theme -eq "")
{ $Theme = "Default Theme" }
else
{ $Theme = $_.Theme }

$SiteInformation = New-Object PsObject
$SiteInformation Add-Member -memberType NoteProperty "Name" -Value $_.Name $SiteInformation Add-Member -memberType NoteProperty "Title" -Value $_.Title $SiteInformation Add-Member -memberType NoteProperty "Description" -Value $_.Description $SiteInformation Add-Member -memberType NoteProperty "Theme" -Value $Theme $SiteInformation Add-Member -memberType NoteProperty "WebTemplate" -Value $_.WebTemplate $SiteInformation Add-Member -memberType NoteProperty "Author" -Value $_.Author $SiteInformation Add-Member -memberType NoteProperty "Created" -Value $_.Created $SiteInformation Add-Member -memberType NoteProperty "Modified" -Value $_.LastItemModifiedDate $SiteInformation Add-Member -memberType NoteProperty "Sites" -Value ($_.Webs).Count $SiteInformation Add-Member -memberType NoteProperty "Users" -Value $_.SiteUsers.Count $SiteInformation Add-Member -memberType NoteProperty "ParentWeb" -Value $_.ParentWeb $SiteInformation Add-Member -memberType NoteProperty "Url" -Value $_.Url $SiteInformation Add-Member -memberType NoteProperty "ServerRelativeUrl" -Value $_.ServerRelativeUrl $SiteInformation Add-Member -memberType NoteProperty "ID" -Value $_.ID
$SiteInformation }}

I am excited to expose more about PowerShell and the useful features it brings to the Sharepoint as an platform so keep looking for furture posts. Thanks !