SharePoint Tech Blog

05/08/2009

SharePoint Profile for Powershell

Filed under: SharePoint — Tags: , , — kctnpblog @ 3:36 am


## SharePoint DLL

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Policy")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Portal")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Publishing")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Administration")

############################################

# Get-SPSite -url

############################################

function global:Get-SPSite($url){

return new-Object Microsoft.SharePoint.SPSite($url)

}

############################################

# Get-SPWeb [-url | -site ]

############################################

function global:Get-SPWeb($url,$site)

{

if($site -ne $null -and $url -ne $null){"Url OR Site can be given"; return}

#if SPSite is not given, we have to get it...

if($site -eq $null){

$site = Get-SPSite($url);

}

#Output 1 or more sites...

if($url -eq $null){

for($i=0; $i -lt $s.AllWebs.Count;$i++){

Write-Output $s.AllWebs[$i]; ##Send through Pipeline

$s.Dispose(); ##ENFORCED DISPOSAL!!!

}

}else{

Write-Output $site.OpenWeb()

}

}

############################################

# Dispose-SPWeb -web -parent

############################################

function global:Dispose-SPWeb($web,$parent=$false){

$site = $web.Site;

$web.Dispose();

if($parent){ $site.Dispose(); }

}

############################################

# Get-SPFarm

############################################

function global:Get-SPFarm(){

return [Microsoft.SharePoint.Administration.SPFarm]::Local

}

############################################

# Get-SPWebApp -url

############################################

function global:Get-SPWebApp($url){
return [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($url)

}

Advertisements

10 Comments »

  1. […] SharePoint site column using PowerShell This code requires the SharePoint Powershell Profile to be loaded beforehand… […]

    Pingback by Create SharePoint site column using PowerShell « SharePoint Tech Blog — 05/08/2009 @ 3:40 am

  2. […] List/Enumerate information management policies on a SharePoint site collection This code requires the SharePoint Profile for PowerShell […]

    Pingback by List/Enumerate information management policies on a SharePoint site collection « SharePoint Tech Blog — 05/08/2009 @ 5:41 am

  3. […] be set using stsadm. Instead, use this Powershell script to run it manually: This code requires the SharePoint Powershell Profile to be loaded beforehand… $farm=[Microsoft.SharePoint.Administration.SPFarm]::Local foreach […]

    Pingback by Execute SharePoint timer job using Powershell « SharePoint Tech Blog — 10/08/2009 @ 4:26 am

  4. […] code requires the SharePoint Powershell Profile to be loaded beforehand $web=Get-SPWeb -url "http://moss/sitedirectory"; […]

    Pingback by Add item to SharePoint list and approve using Powershell « SharePoint Tech Blog — 11/08/2009 @ 7:31 am

  5. […] site directory, it could be modified to read any other list in SharePoint. This code requires the SharePoint Powershell Profile to be loaded beforehand $web=Get-SPWeb -url "http://moss/sitedirectory"; […]

    Pingback by Read SharePoint list using PowerShell « SharePoint Tech Blog — 11/08/2009 @ 10:52 pm

  6. […] one of the out of the box Disposition Approval workflows to a list. This code requires the SharePoint Powershell Profile to be loaded […]

    Pingback by Associate a workflow to a SharePoint list « SharePoint Tech Blog — 14/08/2009 @ 1:56 am

  7. […] one of the out of the box Disposition Approval workflows to a list. This code requires the SharePoint Powershell Profile to be loaded […]

    Pingback by Associate a workflow to a SharePoint list using Powershell « SharePoint Tech Blog — 14/08/2009 @ 1:57 am

  8. […] could be used to set the expiry policy programmatically using PowerShell. This code requires the SharePoint Powershell Profile to be loaded […]

    Pingback by Set expiry policy on SharePoint list using Powershell « SharePoint Tech Blog — 15/08/2009 @ 1:55 pm

  9. […] I find this a bit easier to use since it uses an xml file as its input. This code requires the SharePoint Powershell Profile to be loaded. […]

    Pingback by Create SharePoint Audiences using Powershell « SharePoint Tech Blog — 03/05/2010 @ 12:49 am

  10. […] — Tags: Powershell, SharePoint — kctnpblog @ 8:42 pm This code requires the SharePoint Powershell Profile to be […]

    Pingback by Enumerate SharePoint features using Powershell « SharePoint Tech Blog — 29/07/2010 @ 8:42 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: