Tuesday, June 21, 2016

Running PowerShell on MOSS 2007

Running PowerShell on MOSS 2007


  1. If you are running MOSS 2007 on Windows Server 2003 the you have to download and install PowerShell fromhttp://support.microsoft.com/kb/968930. Windows Server 2008  natively supports PowerShell.
  2. Set the  Execution Policy to ‘RemoteSigned’. You can check it by running ‘Get-ExecutionPolicy’ cmdlet 
    The default execution policy for PowerShell is “Restricted” (commands only, not scripts)
         
# All scripts running locally are allowed
Set-ExecutionPolicy RemoteSigned
This means downloaded scripts must be signed by a trusted publisher before they can be run.
     3. You need to load the SharePoint assemblies with the following command
#    Load the SharePoint assemblies
[Void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
A bunch of PowerShell scripts are available at http://www.powershell.nu/2009/09/08/moss-2007-script-collection

Ref: https://blogs.technet.microsoft.com/praveenh/2013/01/21/running-powershell-on-moss-2007/ 

Ex:1 Retrieve the list of Content Types in MOSS 2007 using PowerShell
MOSS 2007 
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | out-null
Write-host ".."
Write-host ".."
Write-host "Get a list of Content types"
$site = new-object Microsoft.SharePoint.SPSite("http://spweb/extend"); # specify url here
foreach ($web in $site.AllWebs) { 
  $ctypes = $web.ContentTypes
  foreach ($ctype in $ctypes) {
  $usages = [Microsoft.Sharepoint.SPContentTypeUsage]::GetUsages($ctype) 
    foreach ($usage in $usages) { 
    Write-Host $web.Name + "," + $ctype.Name + "," + $usage.Url 
    } 
  }
}

Ex:2 

MOSS 2007 – Find the default view url for all lists in a web app using PowerShell


param
(
    $url = $(Read-Host -Prompt "WebApp Url")
)
# Default View for lists in All Sites
# Lookup Web Application as specified in the command line parameter
$wa = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($url) 
# Create an array 
$sites =@()
Write-Output("`nProcessing sites...`n") 
# Loop through all site collections in the web application
foreach($site in $wa.Sites)
{
    foreach ($s in $site)
    {
        $spWeb = $s.openweb()
            foreach($list in $spweb.lists)
            {
                Write-Host "list:", $list.defaultview.url
            }
    }
}



No comments:

Post a Comment