This article includes the 2007 functions to emulate the SharePoint 2010 cmdlets used in my series of articles in SharePoint Pro Magazine. The first article, Exploring and Inventorying SharePoint Using PowerShell, is here: http://www.sharepointpromag.com/article/sharepoint-server-2010/exploring-inventorying-sharepoint-using-powershell-144834 . Part 2 is here: http://sharepointpromag.com/sharepoint/windows-powershell-scripts-sharepoint-info-files-pagesweb-parts with part 3 to follow.
Check back over the next week or two as I expand this content and add links to download the PowerShell module…
While this little project will in no way include all of the 500 SharePoint 2010 cmdlets, it will provide a core set of cmdlets needed to run my auditing and inventorying SharePoint 2010 PowerShell scripts. These cmdlets are implemented as PowerShell functions so you can study them and enhance them or even use them as models to create additional cmdlets. There will also be links to a download you can simply load them as a PowerShell module.
As a teaser… here's a starter set… (check back in a few days for the full article)
Save the following as SP2007cmdlets.psm1:
#Notes: # The scripts below are from http://TechTrainingNotes.blogspot.com # These scripts may be used in your projects but may not be republised in any form # Formatting data found in SP2007cmdlets.format.ps1xml (optional) function Get-SP2007help { "Currently implemented cmdlets:" " Get-SPFarm" " Get-SPWebApplication" " Get-SPSite" " Get-SPWeb" " Get-SP" } [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") function Get-SPFarm() { [Microsoft.SharePoint.Administration.SPFarm]::Local } function Get-SPWebApplication ($url) { begin { $foundit=$false if ($url -ne $null) { $foundit=$true; [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup("$url") } } process { } end { if ($foundit -eq $false) { [Microsoft.SharePoint.Administration.SPWebService]::ContentService.WebApplications } } } function Get-SPSite ([string]$Identity, [string]$ContentDatabase) { <# .SYNOPSIS Returns all site collections that match the given criteria. .PARAMETER computername The computer name to query. Just one. .DESCRIPTION The Get-SPSite cmdlet returns either a single site that matches the Identity parameter, or all the sites that match the Filter parameter for the specified scope. The scopes are the WebApplication, ContentDatabase , and SiteSubscription parameters. If none of these scopes is provided, the scope is the farm. If the scope is specified with parameter, all sites in that scope are returned. .PARAMETER Identity Specifies the URL or GUID of the site collection to get. The type must be a valid URL, in the form http://server_name or http://server_name/sites/sitename, or a valid GUID (for example, 12345678-90ab-cdef-1234-567890bcdefgh). .PARAMETER ContentDatabase Specifies the GUID of the content database from which to list site collections. The type must be a valid database name, in the form SPContentDB01, or a valid GUID (for example, 12345678-90ab-cdef-1234-567890bcdefgh). #> begin { $foundit=$false if ($Identity -ne "" -or $ContentDatabase -ne "") { $foundit=$true; if ($ContentDatabase -ne "") { if(Test-TTNIsGuid($ContentDatabase)) { Get-SPWebApplication | select -ExpandProperty ContentDatabases | where { $_.id -eq "$ContentDatabase"} | get-spsite } else { Get-SPWebApplication | select -ExpandProperty ContentDatabases | where { $_.name -eq "$ContentDatabase"} | get-spsite } } else { if ($Identity.toLower().StartsWith("http")) { New-Object Microsoft.SharePoint.SPSite("$Identity") } else { New-Object Microsoft.SharePoint.SPSite([guid]"$Identity") } } } } process { if ($_ -ne $null) { $foundit=$true; $_.Sites } } end { if ($foundit -eq $false) { Get-SPWebApplication | Get-SPSite } } } function Get-SPWeb ($url) { begin { if ($url -ne $null) { (New-Object Microsoft.SharePoint.SPSite("$url")).OpenWeb() } } process { $_.AllWebs } } function Test-TTNIsGuid ($guid) { # TechTrainingNotes helper function ($guid -match "^[A-Fa-f0-9]{32}$|({|\()?[A-Fa-f0-9]{8}-([A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12}(}|\))?$|^({)?[0xA-Fa-f0-9]{3,10}(, {0,1}[0xA-Fa-f0-9]{3,6}){2}, {0,1}({)([0xA-Fa-f0-9]{3,4}, {0,1}){7}[0xA-Fa-f0-9]{3,4}(}})$") }
Save the following as SP2007cmdlets.format.ps1xml:
( file to be posted with the complete article )
.