Showing posts with label PowerShell. Show all posts
Showing posts with label PowerShell. Show all posts

3/19/2014

Cincinnati SharePoint User Group March 27th

 

The Cincinnati SharePoint User Group will now be meeting on the 4th Thursday of each month. The next meeting is 3/27/14.

Please register if you will be attending: http://www.meetup.com/TechLife-Cincinnati/events/171195112/

Topic: OneShell | Managing SharePoint Anywhere with Windows PowerShellTopic: Using PowerShell, and a web service call or two, to Administer SharePoint Office 365

Description: With the growing adoption of Office 365 and SharePoint Online and the continued prevalence of SharePoint on-premises, it’s becoming more difficult to manage both environments Scriptamatically™. While SharePoint Online does have native support for Windows PowerShell, there are very few cmdlets to manage the sites and site contents. SharePoint on-premises gives us well over 700 cmdlets, but it still doesn’t answer every situational scenario – leaving gaps in functionality which can be filled by scripters.
In this demo-heavy session, focused on both the developer AND the administrator – you’ll see how you can use OneShell to manage both scenarios (on-premises and Office 365). Demonstrations will focus on building OneShell for both target environments, and by the end of the session you’ll be ready to start Managing SharePoint Anywhere with PowerShell.

Speaker:

Ryan Dennis is a SharePoint Subject Matter Expert with Blue Chip Consulting Group in Central Ohio. Ryan is a Microsoft Certified Solutions Expert with experience in all versions of SharePoint. An accomplished blogger and speaker, he has worked on large-scale SharePoint solutions in the public, non-profit, and private sectors. He focuses primarily on SharePoint architecture, automation, and middle-tier development leveraging out-of-the-box features.

Ryan has worked on projects ranging from large scale Intranet deployments to secure extranets as well as public-facing Internet site deployments. Ryan has a passion for automation, whether it is automating business processes through forms and workflow; or automating deployment, migration and configuration using Windows PowerShell.

And of course... there will be food, door prizes and networking!

We've got books, gadgets and toys!

http://www.CincinnatiSPUG.org

3/04/2014

Cincinnati PowerShell User Group 4/17/14 – SAPIEN Technologies

 

I just got the email below from Rob Dreyer of the Cincinnati PowerShell User Group. Cool stuff!

Mark your calendar! April 17th 2014 at MAX Technical Training in Mason, Ohio.

For more information and to register for the event (free!): http://www.meetup.com/TechLife-Cincinnati/events/154731982/ 


Hello Everyone,

I have some amazing news – our first meeting in 2014 will be extra special. Throughout 2014, Dr. Ferdinand Rios, the CEO of SAPIEN Technologies, Inc. is touring around the world. Last week, I received word that on Thursday April 17th he will be coming to MAX! I nearly fell out of my seat when I heard.

 

clip_image002clip_image004clip_image005clip_image007clip_image009

And, if you haven’t tried PrimalScript or PowerShell Studio, now is the time!

clip_image010

Check out the links below for more details. Thanks, Ferdinand!

Free Software Upgrades: http://www.sapien.com/blog/2014/02/13/2014-versions-out-march-15-buy-now-and-save/

Free PowerShell Training: http://www.sapien.com/blog/2013/12/23/sapiens-full-powershell-video-catalog-now-on-you-tube/

Let’s plan to give him a warm welcome. We’ll be hosting the event at MAX, but I will also provide remote access using GoToMeeting for those who cannot attend. I’ll send meeting information out as we get closer to the event. Hope to see you soon!

2/20/2014

Download a File from SharePoint using PowerShell

 

I recently had a request for a PowerShell script that could be run as a Windows scheduled task to download a file each night to a network share. As is typical, there's more than one way…

 

The PowerShell / .Net approach:

This is a ".Net approach" as it does not use any PowerShell cmdlets (beyond New-Object). The following will work from all versions of PowerShell and SharePoint 2007 – 2013, but not Office 365. It will work from any client PC as long as you have permissions to access the file. Why not Office 365? O365 requires an authentication cookie. (When I get some time I'll post an O365 version.)

$fromfile = "http://yourserver/sites/yoursite/shared%20documents/yourfile.xlsx"
$tofile   = "c:\somedirectory\yourfile.xlsx"

$webclient = New-Object System.Net.WebClient

$webclient.UseDefaultCredentials = $true
#  or
# $webclient.Credentials = …
$webclient.DownloadFile($fromfile, $tofile)

 

The SharePoint Approach:

This approach must be run from a SharePoint server and uses the Get-SPWeb cmdlet to access a site. As it is much more complicated, why would you ever use it? To do more complex things! Things like getting all of the files from a library and then downloading them (in a foreach loop), ZIPing the file(s) before download or otherwise manipulating the files before download.

The following will work from the SharePoint 2010 and 2013 Management Shells (but not for Office 365). Why not Office 365? The following needs to be run on the SharePoint server, and you are not allowed to do that with O365.

$fromsite = "http://yourserver/sites/yoursite"

$fromfile = "yourlibrary/yourfile.xlsx"
$tofile   = "c:\test\yourfile.xlsx"

$web = Get-SPWeb $fromsite
$file = $web.GetFile($fromfile)
$filebytes = $file.OpenBinary()

$filestream = New-Object System.IO.FileStream($tofile, "Create")
$binarywriter = New-Object System.IO.BinaryWriter($filestream)
$binarywriter.write($filebytes)
$binarywriter.Close()

 

.

10/21/2013

Cincinnati SharePoint User Group 10/24/13

 

I'll be speaking at the Cincinnati User Group this Thursday, 10/24/13. See you there!


The Cincinnati SharePoint User Group will now be meeting on the 4th Thursday of each month. The next meeting is 10/24/2013. Same location and same time, just a different day!

Speaker: Mike Smith

MVP SharePoint, Senior instructor at MAX Technical Training, Computer professional (computer nut) since 1980, Courseware author, Book author (SharePoint 2007 & 2010 Customization for the Site Owner), Speaker at SharePoint events, toy airplane pilot..

Topic: Using PowerShell, and a web service call or two, to Administer SharePoint Office 365

In this presentation we will combine the recently released SharePoint Online Management Shell PowerShell module, the Microsoft Online Services PowerShell module and a few PowerShell web services calls to management SharePoint Online. By the end of the session we will have a complete script to create a SharePoint classroom or team collaboration environment in the cloud!

We will use the Microsoft Online Services to add users, passwords and manage licenses.

We will use the SharePoint Online Management Shell to create Site Collections, add users and add groups.

We will use web services to create subsites, lists and libraries.

And of course... there will be food, door prizes and networking!

http://www.CincinnatiSPUG.org

8/02/2013

PowerShell to the rescue (again!)

 

Using PowerShell to replace text in a file.

I have a custom class next week. I need to make a little fix to the lab files… actually 526 .css files and 380 .htm files need to be updated with several fixes in each. Lots of little fixes.

 

How did I know how many files?  PowerShell of course…

(Get-ChildItem *.css –Recurse).count

 

Find and replace some text…

First update was to fix some URLs. I needed to remove a backslash at the start of every "href=" and "src=".  A little PowerShell could also do all of the file edits!

$from = 'href="/'
$to = 'href="'

Get-ChildItem *.htm -recurse |
%{
     $name = $_.fullname; Write-Host $name; (Get-Content $name) |
     %{ $_ -replace $from,$to } |
     Set-Content -path $name –force
}

I wrapped the above line in a function, called it eight times with my eight replacements, and it was done in seconds!

 

Notes:

Find all of the files…

  Get-ChildItem *.htm -recurse

and run some code on each one:

   %{   }

Save the file path to a variable, display the file path and then get the file's contents:

   $name = $_.fullname;
   Write-Host $name;
  (Get-Content $name)

The pipe then has the text to be replaced, so let's do the replace:

   %{ $_ -replace $from, $to }

And write the replaced text out to a file with the same name:

   Set-Content -path $name –force

 

.

6/02/2013

SharePoint Versioning Trivia, or maybe a start on a versioning FAQ

 

The number of versions retained is one more than the limit you set. Entering 10 as the version limit will keep up to 11 versions of the item. I guess the current "version" is not counted as a "version".

image

Then maximum number of versions per item is 5000. (at least in SP 2010)

image

We you exceed the version limit the oldest item is immediately discarded. It is not moved to the recycle bin.

Only libraries support Minor or Draft versioning. Lists only support major versions.

The maximum number of draft versions is 511, and you can't change that number. Attempting to create a 512th draft version generates this error:

image

"Keep drafts for the following number of major versions" will automatically discard minor versions of published major versions over the entered limit. Actually… it will keep one less than you probably expect.

image

For example, if the limit is 3 and you have some unpublished drafts, then you will see drafts from the previous 2 published versions plus the current drafts:

image   (click image to enlarge)

Notice that you see 13.1, 14.1, 15.1 and 15.2, but not 12.1. Three sets of drafts as expected. Now let's publish 15.2 into 16.0:

image(click image to enlarge)

Now we only have two sets of drafts, 14.1 and 15.1.

 

Clicking "Delete All Versions" actually deletes all but one version. The latest version is retained.

Reducing the version limit will not automatically delete excess old versions. The excess old versions will be deleted the next time the item is deleted. (You can create a PowerShell script to clean out the excess versions.)

Visitors to the site can see all of the old versions by default. You may want to edit the Read and View Only permissions levels to remove the "View Versions" permission.

Major version numbers are assigned internally using “version number” times 512. You can see this when display a version of a list item. Example of a direct URL: http://intranet /Lists/Announcements/DispForm.aspx?ID=1&VersionNo=1024
No that’s not version 1,024! Version numbers are assigned using “version number” times 512. Version 1 is 512, version 2 is 1024, version 3 is 1536 (i.e. 3 * 512), version 4 is 2048 (i.e. 4 * 512) …

 

Notes for developers and PowerShell scripters:

Versioning related properties of SPListI:

  • .MajorVersionLimit – the "Keep the following number of major versions" field in Versioning Settings
  • .MajorWithMinorVersionsLimit - the "Keep drafts for the following number of major versions" field in Versioning Settings

Versioning related properties of SPListItem:

  • .Versions – a collection of retained versions
  • .Versions.Count
  • .Version[0]  gets the most recent version of the item
  • .Verions[x] where x is .Versions.Count, is the oldest version of the item (i.e. versions are stored in reverse order)
  • .HasPublishedVersion   -  boolean

 

Here's a little PowerShell script that will take the first document (ID=1) in the Shared Documents library and create 10 major versions, each with two minor versions.

# before running this, enable major and minor versioning on the library

# get the web site
$web = Get-SPWeb http://intranet.contoso.com

# publish the first document 10 times
for ($versionsToCreate=0; $versionsToCreate -lt 10; $versionsToCreate++)
{
  # get the document
  $doc = $web.lists["Shared Documents"].getitembyid(1)

  # create two minor versions
  for ($x=0; $x -lt 2; $x++) { $doc.update() }

  # publist the last minor as a major version
  $doc.File.publish("")
}

1/23/2013

Cincinnati PowerShell User Group Meeting with Keith Mayer (Round 2)

 

Thursday 1/24/2013 6:00 at MAX Technical Training

Before our December meeting came to a close, Keith mentioned a follow-up presentation. I am pleased to announce he will be joining us again on Thursday January 24th! He will continue his presentation with the second half of PowerShell management and virtualization – this time with a focus on managing Windows Azure virtual machines via PowerShell.

Registration and other details here: http://www.meetup.com/TechLife-Cincinnati/events/98558502/

Registration is optional, but helps us with planning.

.

12/28/2012

Fun and Games with Site Collection Administrators

 

SharePoint has three kinds of Site Collection Administrators: Primary, Secondary and "other". When you edit the list of admins in Site Actions, Site Settings there is just a list of admins with no indication of kind. So who is the Primary? What happens when the list is edited and the Primary and / or Secondary is removed? Then who's the Primary?

This article has two parts:

  • Background on Site Collection Administrators
  • Weird Fun and Games

I did my testing in SharePoint 2010, but expect similar results in both 2007 and 2013. I'll test those when I get a chance.

Background

A Site Collection Administrator is:

  • a user assigned to the SPSite.Owner property. They are displayed in Central Administration as the "Primary site collection administrator".
  • a user assigned to the SPSite.SecondaryContact property. They are displayed in Central Administration as the "Secondary site collection administrator".
  • a user added in Site Actions, Site settings as a site collection administrator. They are not displayed anywhere in Central Administration. They are added in the site using Site Actions, Site Settings, Site Collection Administrators. (Both these admins and the Primary and Secondary admins have their SPUser.IsSiteAdmin property set to true.)

What makes them special:

  • All Site Collection Administrators have full control over the entire site collection and can see all content. (unless limited by Central Administration, Applications, User Policy)
  • Only the Primary and Secondary admins receive administrative email alerts for the site collection (Quota exceeded warnings and Site Use Confirmation and Deletion notices)

Finding them with Central Administration

image

Finding them with Site Actions, Site Settings

image

Finding them with PowerShell (just the Primary and Secondary here:

$site = get-spsite http://sharepoint/sites/training
$site.Owner
$site.SecondaryContact

Or for all Site Collections in a web application:

Get-SPWebApplication http://sharepoint | Select -ExpandProperty sites | Select url, owner, secondarycontact | ft -AutoSize

Now for the Fun and Games!

I created a new site collection and assigned:

  • Primary Site Collection Administrator (Owner):  susanj
  • Secondary Site Collection Administrator (SecondaryContact):  samc

I confirmed the admins in:

Central Admin:

image

Site Actions, Site Settings:

image

PowerShell:

Get-SPSite http://sharepoint/sites/test1 | select url, owner, secondarycontact

Url                           Owner             SecondaryContact
---                           -----             ----------------
http://sharepoint/sites/test1 SHAREPOINT\susanj SHAREPOINT\samc

 

Now I add two more Site Collection Administrators from Site Actions, Site Settings:

image

No change in Central Administration as these new admins are not the Primary/Owner or Secondary/SecondaryContact and have been added as "other site collection admins". (Their IsSiteAdmin property has been set to True.)

For PowerShell we need to add one more request to get the list of "other" admins (IsSiteAdmin=true)…

$site = Get-SPSite http://sharepoint/sites/test1
$web = $site.RootWeb
$web.AllUsers | Select UserLogin, IsSiteAdmin 

UserLogin                IsSiteAdmin
---------                -----------
SHAREPOINT\samc                 True
SHAREPOINT\administrator        True
SHAREPOINT\stellas              True
SHAREPOINT\susanj               True
SHAREPOINT\system              False

So now I have:

  • Primary Site Collection Administrator (Owner): susanj
  • Secondary Site Collection Administrator (SecondaryContact): samc
  • Additional admin: stellas
  • Additional admin: administrator

 

Now for the fun…

I logged in as Stella and then using Site Actions, Site Settings I removed sam and susan (the Primary and Secondary). So who is now what?

  • Primary Site Collection Administrator (Owner): stellas
  • Secondary Site Collection Administrator (SecondaryContact): none!
  • Additional admin: administrator

Then I added susan and sam back:

  • Primary Site Collection Administrator (Owner): stellas
  • Secondary Site Collection Administrator (SecondaryContact): none!
  • Additional admin: administrator
  • Additional admin: samc
  • Additional admin: susanj

I then tried all kinds of combinations of adding and removing admins from Site Actions, Site Settings and from Central Admin.

Learnings

  • There are two kinds of Site Collection Administrators: the ones who receive site event emails, and all of the rest. Except for the emails, they all have the same permissions.
  • The order of site collection administrators in Site Actions, Site Settings does not tell us who is the Primary or the Secondary. The order is simply the order the users are found in the SPWeb.AllUsers collection, sorted by DisplayName. There is no way to find out who the Primary or Secondary is except for Central Administration and PowerShell.
  • If a Primary Site Collection Administrator is deleted from Site Actions, Site Settings, a replacement is automatically selected using the first person found in order by ID. (ID's are assigned in the order users are added to the site collection. First user is ID #1, etc..)
  • If a Secondary Site Collection Administrator is deleted from Site Actions, Site Settings, a replacement is not automatically selected. A Secondary Site Collection Administrator can only be added from Central Administration or by using PowerShell.

Obvious, right?

 

.

 

 

 

 

 

 

 

 

    a

12/04/2012

SharePoint 2007 PowerShell cmdlets

 

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 )
 
. 

11/05/2012

SharePoint 2013 Education Templates

 

Does SharePoint 2013 have built-in education related sites, quizzes and tools for schools?

I'm starting my prep for the future SharePoint 2013 exams. In looking at the new PowerShell commands (there are 199 of them! 572 vs 771) I ran across these: Install-SPEduSites and New-SPEduClass. So far I can't find anything official on these new "education" features. PowerShell's help command only lists the name of the cmdlet and no description or other details.

  image

Below is all I've found so far. I'll update this as I find more… and please post comments to anything you may find. This may be an incomplete feature that may never be supported in 2013, or it may be a feature that becomes official in a future service pack, or it may only be available under a special school only edition. Who knows at this point…

 

What I've found so far:

Microsoft Goes Back to School and Gets Smart: SharePoint 2013 & Education Services
http://www.cmswire.com/cms/information-management/microsoft-goes-back-to-school-and-gets-smart-sharepoint-2013-education-services-017197.php

SharePoint Education – Installing and Configuring
http://blog.furuknap.net/sharepoint-education-installing-and-configuring

Some key SharePoint 2013 features (scroll down towards the end to find "Education Services"): (thanks Tanya for the link!)
http://www.sharepointgeoff.com/sharepoint-2013-features/

It appears to be managed from Central Administration:
http://imageshack.us/photo/my-images/831/centrald.png/

A question has been posted in the MSDN/TechNet forums, so a discussion has been started here:
http://social.msdn.microsoft.com/Forums/en-US/sharepointgeneral/thread/4851485e-5089-494b-bddd-1362eaebb0bf

 

.

10/18/2012

SharePoint Saturday Cincinnati 2012–Oct. 27th

 

Are you registered yet?

SharePoint Saturday Cincinnati

Saturday, October 27, 2012

Event details, including speakers and topics have been posted!
Go here for details: http://www.sharepointsaturday.org/cincinnati

Register here: http://spscincinnati2012.eventbrite.com/

Twitter: #SPSCincinnati

sps-cincinnati-speaker-badge_thumb

My topic will be "Exploring and Auditing SharePoint Using PowerShell"

This session shows how to use PowerShell in both SharePoint 2007 and 2010 to find and extract all kinds of information not easily found using built-in features. In this session you will see how to use PowerShell to:

• Find all documents in any site, or the entire farm, that matches a pattern (example: *.avi)
• Find all users who have access to a particular file (or folder, or library or site)
• Find sites with no recent activity
• Find all content a single user has access to
• Find all libraries that use a selected Content Type
• Find all customized (un-ghosted) pages
• Find all pages that use a selected web part
• How to collect the results into reports
• and more…

10/17/2012

Cincinnati PowerShell Events

 

Cincinnati PowerShell User Group

The next meeting of the Cincinnati PowerShell User Group is Thursday October 18th at MAX Technical Training. I'll be speaking on "How to use PowerShell to use, filter and merge data from multiple systems". I'll be showing how to work across three systems, AD, SharePoint and SQL to collect data about a subset of employees and post the results to a SharePoint list.

Go here to resister (not required to attend) http://www.meetup.com/TechLife-Cincinnati/events/84008152/

 

SharePoint Saturday Cincinnati

It's a SharePoint event, but there will be PowerShell content there! At least four sessions include PowerShell.

Go here for info and to register: http://www.sharepointsaturday.org/cincinnati
October 27th, 2010

.

10/10/2012

SharePoint–Finding Column Display and Internal Names

 

Many customizer and developer projects require knowing the "internal names" for list and library fields. For example the task list field "% Complete" is internally named "PercentComplete".

Here are a few ways to find the internal name:

  • From the browser
  • From SharePoint Designer
  • Using PowerShell
  • Using a C# Console Application
  • Using the Client Side Object Model
  • Using JavaScript Client Side Object Model and a Content Editor Web Part

    Pretty much something for everyone!

 

From the browser

Permissions needed: Must have Site Owner (Full Control) or Design permissions

This could be a bit tedious if you wanted to check all of the fields, but for just one it's quick.

  1. Display the list or library and click the List or Library Ribbon
  2. Click List or Library Settings
  3. Scroll down to the list of columns and click the column name
  4. Note the URL for the page… the internal name is listed at the end: 
        http://………&Field=Author

 

From SharePoint Designer

Permissions needed: Must have Site Owner (Full Control) or Design permissions (may only need edit permissions in the library holding the web part page… To Do for Mike: need to test this!)

  1. In SharePoint Designer 2010 open your site and edit a web part page
  2. Click in a web part zone, click the Insert ribbon tab, click Data View and Empty Data View
  3. Click "Click here to select a data source" and pick your list
  4. In the Data Source Details pane mouse over the sample data (or the blank area below the field name) and the XSLT path the field will be displayed. The value after the "@" is the internal name.
    image

 

Using PowerShell

Permissions needed: Administrator access to the server and permissions to the site (PowerShell is an administrator's tool)

$web = Get-SPWeb http://sharepoint/sites/training/salestraining
$list = $web.Lists["Announcements"]
$list.fields | select Title, InternalName, Hidden, CanBeDeleted | sort title | ft -AutoSize

As you will most often be interested in the non-hidden fields, you can add a Where to filter them:

$list.fields | select Title, InternalName, Hidden, Sealed, CanBeDeleted | where {$_.Hidden -eq $false} | sort title | ft –AutoSize
 

Using a C# Console Application

Permissions needed: Administrator access to the server and permissions to the site (the code must run on the server)

using System;
using Microsoft.SharePoint;  // add a reference to Microsoft.SharePoint

// remember to change the Build Platform Target to x64!
namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            SPSite site = new SPSite("http://sharepoint/sites/Training/");
            SPWeb web = site.AllWebs["salestraining"];
            SPList list = web.Lists["Announcements"];

            Console.WriteLine("Title - Internal Name - Hidden - CanBeDeleted");
            foreach (SPField f in list.Fields)
            {
                Console.WriteLine("{0} - {1} - {2} - {3}", f.Title, f.InternalName, f.Hidden, f.CanBeDeleted);
            }
            site.Dispose();
            Console.ReadLine();
        }
    }
}

 

Using the Client Side Object Model

Permissions needed: May only need view permissions in the library holding the web part page… (To Do for Mike: need to test this!)

You can write and run Client Side Object Model (CSOM) code from your local PC and not need access to the SharePoint Servers. The following is a little console application with references added for Microsoft.SharePoint.Client and Microsoft.SharePoint.Client.Runtime.

using System;

using Microsoft.SharePoint.Client;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            string url = "http://sharepoint/sites/training";
            ClientContext context = new ClientContext(url);
            Web web = context.Web;
            var list = web.Lists.GetByTitle("Announcements");

            context.Load(list.Fields);
            context.ExecuteQuery();

            Console.WriteLine(list.Fields.Count);
            foreach (Field f in list.Fields)
            {
                Console.WriteLine("{0} - {1} - {2} - {3}", f.Title, f.InternalName, f.Hidden, f.CanBeDeleted);
            }
            Console.ReadLine();
        }
    }
}

 

Using JavaScript Client Side Object Model and a Content Editor Web Part

Permissions needed: May only need view permissions to view the page… (To Do for Mike: need to test this!)

image

Steps:

  1. Open Notepad and copy and paste the code below
  2. Save the file as GetFieldName.htm
  3. Upload the file to a library (SiteAssets, Shared Documents, etc.)
  4. Right-click the uploaded file and copy the shortcut (the URL)
  5. Go to a web part page or the home page and add a Content Editor Web Part
  6. Edit the web part and set the Content Link to the URL of the file you just uploaded
  7. Save your changes and test!

                  image

<input type="text" id="ListName" value="Tasks"></input>
<button onclick='GetFieldList()'>Get Field List</button>

<script type="text/javascript">

function GetFieldList()
{
  var listname = document.getElementById("ListName").value;
  var ctx = SP.ClientContext.get_current();
  this.web = ctx.get_web();
  ctx.load(this.web);
  this.list = web.get_lists().getByTitle(listname);
  ctx.load(this.list);
  this.fields = this.list.get_fields();
  ctx.load(this.fields); 

  ctx.executeQueryAsync(Function.createDelegate(this, this.getListInfoSuccess), Function.createDelegate(this, this.getListInfoFail));
}

function getListInfoSuccess(sender, args) 
{
        var fieldEnumerator = this.fields.getEnumerator(); 
        var results="";
        while (fieldEnumerator.moveNext()) { 
            var oField = fieldEnumerator.get_current(); 
            if (!oField.get_hidden())
            results+= oField.get_title()
                + " - " + oField.get_internalName()
                + " - " + oField.get_hidden()
                + "\n";
        }
        alert(results);
}    
function getListInfoFail(sender, args) 
{
 alert('Something failed. Error:'+args.get_message());    
}

</script>

9/23/2012

SharePoint Saturday Cincinnati 2012–Oct. 27th

 

SharePoint Saturday Cincinnati

Saturday, October 27, 2012

Event details, including speakers and topics have been posted!
Go here for details: http://www.sharepointsaturday.org/cincinnati

Register here:  http://spscincinnati2012.eventbrite.com/

Twitter: #SPSCincinnati

sps-cincinnati-speaker-badge

My topic will be "Exploring and Auditing SharePoint Using PowerShell"

This session shows how to use PowerShell in both SharePoint 2007 and 2010 to find and extract all kinds of information not easily found using built-in features.  In this session you will see how to use PowerShell to:
 
• Find all documents in any site, or the entire farm, that matches a pattern (example: *.avi)
• Find all users who have access to a particular file (or folder, or library or site)
• Find sites with no recent activity
• Find all content a single user has access to
• Find all libraries that use a selected Content Type
• Find all customized (un-ghosted) pages
• Find all pages that use a selected web part
• How to collect the results into reports
• and more…

8/26/2012

Final Reminder! First Ever Cincinnati PowerShell User Group Meeting 8/28!

 

Tuesday, August 28, 2012, 6:00 PM to 8:00 PM (add it to your calendar NOW!)

It's free! Go here and register NOW!
http://www.meetup.com/TechLife-Cincinnati/events/75092962/
(Registration is not required, but will help us plan for the event, order pizza and spread the word.)

Speaker is scheduled, SWAG is being acquired, people are signing up.

Ed Wilson, the Microsoft Scripting Guy and a well-known scripting expert, will be the kick off speaker for the new Cincinnati PowerShell user group. His topic will be "Using Windows PowerShell 3.0 to manage the remote Windows 8 workstation".

Goodies are on the way from Microsoft Press, O'Reilly, APress and others! Free books, discounts, and other stuff, all to be given away as door prizes. (But I know you are coming to hear Ed speak, not to win door prizes!)

Come prepared to network, talk PowerShell and even volunteer to support this new user group!

Spread the word!

Let your coworkers know. Blog and Tweet about it. (#cincypowershell should work)

Ed's Topic "Using Windows PowerShell 3.0 to manage the remote Windows 8 workstation"

There are four different ways to manage a remote Windows 8 workstation. The first is to use WMI remoting, the second is to use the computername cmdlets, the third is to use WinRm and Windows PowerShell native remoting, the last way is to use the CIM cmdlets. Each approach has advantages and disadvantages for the network administrator. In this session, I will examine each approach, and provide a checklist of criteria to aid the enterprise network administrator in choosing the appropriate technology for a variety of real world scenarios. This presentation combines live demo’s and interactive discussion to heighten learning.

About the presenter:

Ed Wilson is the Microsoft Scripting Guy and a well-known scripting expert. He writes the daily Hey Scripting Guy! blog. He has also spoken multiple times at TechEd as well as at the Microsoft internal Tech Ready and Geek Ready conferences. He has also spoken at the first SQL Rally conference in Orlando, as well as at numerous SQL Saturday events. He is a Microsoft-certified trainer who has delivered a popular Windows PowerShell workshop to Microsoft Premier Customers worldwide. He has written 9 books including 6 on Windows scripting that were published by Microsoft Press. He has also contributed to nearly a dozen other books. His Windows PowerShell 2.0 Best Practices book for Microsoft Press is currently a best seller. Ed holds more than 20 industry certifications, including Microsoft Certified Systems Engineer (MCSE), the Microsoft Certified Data Base Administrator (MCDBA) and Certified Information Systems Security Professional (CISSP). Prior to coming to work for Microsoft, he was a senior consultant for a Microsoft Gold Certified Partner where he specialized in Active Directory design and Exchange implementation. In his spare time, he enjoys woodworking, underwater photography, and scuba diving.

.

8/24/2012

SharePoint PowerShell cmdlets Equivalents for SharePoint 2007

 

SharePoint 2007 administrators may feel a bit left out when the see all of the articles showing how to do quick and powerful things with SharePoint 2010 PowerShell cmdlets. In this article I will show how to create common SharePoint objects without using the cmdlets.

This article is not done… I will be adding to it. Let me know if you need any other cmdlet replacements. When I get a chance I'll wrap up and publish my collection of 2007 "cmdlets" so you can generally just use the 2010 scripts.

 

Most of the examples below are in the form of "replace this cmdlet based code fragment with this SharePoint API fragment".

 

Hooking PowerShell to the SharePoint API

For all of the following script samples start your script with this line:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

This line is only need once at the beginning of your script.

 

Get-SPFarm

Replace:
  $farm = Get-SPFarm

With:
   $farm = [Microsoft.SharePoint.Administration.SPFarm]::Local

Notes:

  • The cmdlet's default property is the name of configuration database. OM's default return is a list of all properties.
  • The output of the above can be piped just like Get-SPFarm.
      [Microsoft.SharePoint.Administration.SPFarm]::Local | select servers
    or
      $farm | select servers

 

Get-SPSite

Returned Data with URL parameter

Replace:
  $site = Get-SPSite http://intranet

With:
  $site = New-Object Microsoft.SharePoint.SPSite("http://intranet")

Notes:

  • The cmdlet's default property is the Url of the site collection. OM's default return is a list of all properties.
  • The output of the New-Object can be piped to another cmdlet just like Get-SPSite. You cannot pipe into New-Object.

 

Target of a Pipe passing a SPWebApplication or a collection of SPWebApplications

Replace:
$webapplication | Get-SPSite

With:
$webapplication | select -ExpandProperty Sites

Examples:
  2010: $webapplication | Get-SPSite | Select url, {$_.rootweb.title}
  2007: $webapplication | select -ExpandProperty Sites | Select url, {$_.rootweb.title}

 

Get-SPWeb

Returned Data with URL parameter

Replace:
  $site = Get-SPWeb http://intranet/sailboat

With:
  $web = (New-Object Microsoft.SharePoint.SPSite("http://intranet/blog")).OpenWeb()
or
  $web = (New-Object Microsoft.SharePoint.SPSite("http://intranet")).allwebs["sailboat"]

Notes:

  • The above is identical to the Get-SPSite replacement with the addition of .OpenWeb().
  • Get-SPWeb typically is used with "-Limit All" to display more than 20 webs. That is not needed with the 2007 equivalent which will always return all webs.

 

Target of a Pipe passing a collection of SPSites

Replace:
  collectionOfSites | Get-SPWeb

With:
  collectionOfSites | select -ExpandProperty AllWebs

Examples:
  2010: $webapplication.Sites | Get-SPWeb | Select title, url
  2007: $webapplication.Sites | select -ExpandProperty AllWebs | Select title,url

 

Get-SPWebApplication

Returned Data using URL parameter

Replace:
  $webApplication = Get-SPWebApplication http://servername

With:
$webApplication = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup("http://servername")

 

Returned Data without parameter (return all web apps)

Replace:
$webApplications = Get-SPWebApplications

With:
$webApplications = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.WebApplications

 

more to come…

8/22/2012

SharePoint: PowerShell to find all Content Types that use a Site Column

 

Just another little PowerShell script for SharePoint…

The following will report all Content Types in a single Site Collection that uses a particular Site Column.

This is related to this article PowerShell to find SharePoint Content Types.

 

The Script:

$site = Get-SPSite http://sharepoint/sites/training   #your URL here!
$web = $site.RootWeb

# Get the GUID of your Site Column
$guid = $fields["End Time"].id            # your Site Column name here

# Find all content types that use that column type
#  This will display all content types and list details if there match for the column


$ct = $web.AvailableContentTypes 
for ($i=0; $i -lt $ct.Count; $i++) 
{
  for ($j=0; $j -lt $ct[$i].Fields.Count; $j++) 
  {
    if ($ct[$i].Fields[$j].id -eq $guid)
    {
      Write-Host $ct[$i].Name " has column"
    }
  }
}

 

For SharePoint 2007 replace the first line with these two:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

$site = New-Object Microsoft.SharePoint.SPSite(http://yourserver/sites/yoursite)

 

.

8/17/2012

Final Reminder! First Ever Cincinnati PowerShell User Group Meeting 8/28!

 

Tuesday, August 28, 2012, 6:00 PM to 8:00 PM (add it to your calendar NOW!)

It's free! Go here and register NOW!
http://www.meetup.com/TechLife-Cincinnati/events/75092962/
(Registration is not required, but will help us plan for the event, order pizza and spread the word.)

Speaker is scheduled, SWAG is being acquired, people are signing up.

Ed Wilson, the Microsoft Scripting Guy and a well-known scripting expert, will be the kick off speaker for the new Cincinnati PowerShell user group. His topic will be "Using Windows PowerShell 3.0 to manage the remote Windows 8 workstation".

Goodies are on the way from Microsoft Press, O'Reilly, APress and others! Free books, discounts, and other stuff, all to be given away as door prizes. (But I know you are coming to hear Ed speak, not to win door prizes!)

Come prepared to network, talk PowerShell and even volunteer to support this new user group!

 

Spread the word!

Let your coworkers know. Blog and Tweet about it. (#cincypowershell should work)

 

Ed's Topic "Using Windows PowerShell 3.0 to manage the remote Windows 8 workstation"

There are four different ways to manage a remote Windows 8 workstation. The first is to use WMI remoting, the second is to use the computername cmdlets, the third is to use WinRm and Windows PowerShell native remoting, the last way is to use the CIM cmdlets. Each approach has advantages and disadvantages for the network administrator. In this session, I will examine each approach, and provide a checklist of criteria to aid the enterprise network administrator in choosing the appropriate technology for a variety of real world scenarios. This presentation combines live demo’s and interactive discussion to heighten learning.

About the presenter:

Ed Wilson is the Microsoft Scripting Guy and a well-known scripting expert. He writes the daily Hey Scripting Guy! blog. He has also spoken multiple times at TechEd as well as at the Microsoft internal Tech Ready and Geek Ready conferences. He has also spoken at the first SQL Rally conference in Orlando, as well as at numerous SQL Saturday events. He is a Microsoft-certified trainer who has delivered a popular Windows PowerShell workshop to Microsoft Premier Customers worldwide. He has written 9 books including 6 on Windows scripting that were published by Microsoft Press. He has also contributed to nearly a dozen other books. His Windows PowerShell 2.0 Best Practices book for Microsoft Press is currently a best seller. Ed holds more than 20 industry certifications, including Microsoft Certified Systems Engineer (MCSE), the Microsoft Certified Data Base Administrator (MCDBA) and Certified Information Systems Security Professional (CISSP). Prior to coming to work for Microsoft, he was a senior consultant for a Microsoft Gold Certified Partner where he specialized in Active Directory design and Exchange implementation. In his spare time, he enjoys woodworking, underwater photography, and scuba diving.

.

7/26/2012

New Cincinnati PowerShell User Group!

 

Tuesday, August 28, 2012, 6:00 PM to 8:00 PM (add it to your calendar NOW!)

Ed Wilson, the Microsoft Scripting Guy and a well-known scripting expert, will be the kick off speaker for the new Cincinnati PowerShell user group. His topic will be "Using Windows PowerShell 3.0 to manage the remote Windows 8 workstation".

Come prepared to network, talk PowerShell and even volunteer to support this new user group!

It's free! Go here and register!
http://www.meetup.com/TechLife-Cincinnati/events/75092962/

Registration is not required, but will help us plan for the event, order pizza and spread the word!

 

Ed's Topic "Using Windows PowerShell 3.0 to manage the remote Windows 8 workstation"

There are four different ways to manage a remote Windows 8 workstation. The first is to use WMI remoting, the second is to use the computername cmdlets, the third is to use WinRm and Windows PowerShell native remoting, the last way is to use the CIM cmdlets. Each approach has advantages and disadvantages for the network administrator. In this session, I will examine each approach, and provide a checklist of criteria to aid the enterprise network administrator in choosing the appropriate technology for a variety of real world scenarios. This presentation combines live demo’s and interactive discussion to heighten learning.

 

About the presenter:

Ed Wilson is the Microsoft Scripting Guy and a well-known scripting expert. He writes the daily Hey Scripting Guy! blog. He has also spoken multiple times at TechEd as well as at the Microsoft internal Tech Ready and Geek Ready conferences. He has also spoken at the first SQL Rally conference in Orlando, as well as at numerous SQL Saturday events. He is a Microsoft-certified trainer who has delivered a popular Windows PowerShell workshop to Microsoft Premier Customers worldwide. He has written 9 books including 6 on Windows scripting that were published by Microsoft Press. He has also contributed to nearly a dozen other books. His Windows PowerShell 2.0 Best Practices book for Microsoft Press is currently a best seller. Ed holds more than 20 industry certifications, including Microsoft Certified Systems Engineer (MCSE), the Microsoft Certified Data Base Administrator (MCDBA) and Certified Information Systems Security Professional (CISSP). Prior to coming to work for Microsoft, he was a senior consultant for a Microsoft Gold Certified Partner where he specialized in Active Directory design and Exchange implementation. In his spare time, he enjoys woodworking, underwater photography, and scuba diving.

.

6/26/2012

SharePoint: Search and Replace in Content Editor Web Parts

 

If you are interested in the use of these types of PowerShell scripts to explore and audit SharePoint then you may want to attend my “Exploring and Auditing SharePoint Using PowerShell” session at SharePoint Saturday Dayton this Saturday.

 

 

There’s a question in the MSDN SharePoint forums about how to update Content Editor Web Parts in hundreds of web part pages. These web parts had URLs that pointed to a server that had been renamed, and to fix the URLs meant updating all of these Content Editor Web Parts.

I had recently written a little script to find all of the Content Editor Web Parts in a farm that had a certain piece of text. It only took a small edit to add some code to find and replace text. I have posted the script here instead of the forums as I plan to return here to clean up the code a bit and add more comments.

 

As this script will change, and possibly break, your Content Editor Web Parts… what's below is provided with no warranties and is up to you to test to confirm that it is safe!

 

Steps:

  1. Paste the following into a NotePad file and save as CEWPsearchandreplace.ps1 (or any name you like)
     
  2. Edit these two lines with your before and after text:
        $textToFind = "theBeforeText"
        $newText    = "theAfterText"
     
  3. Start the SharePoint 2010 Management Shell and type: 
          . c:\whereyousavedit\CEWPsearchandreplace.ps1
    Note the dot and the space before the C:

Note that you will need appropriate PowerShell and SharePoint permissions to run this script. See here for more info on permissions: http://techtrainingnotes.blogspot.com/2011/08/searching-and-auditing-sharepoint-with.html

 

Code Notes:

  • The code creates three functions:
    Get-SPWebPartsForWeb  yourURL                (for a single site)"
    Get-SPWebPartsForSite  yourURL                 (for all sites in a site collection)"
    Get-SPWebPartsForApplication  yourURL    (for all site collections in an app)"
     
  • The code only checks for web part pages in selected libraries: "Site Pages","SitePages","Pages"
    You can edit the $librariesToCheck variable to add more locations
     
  • The code also checks the default.aspx page in the site root if $checkrootdefaultaspx = $true
     
  • There are a number of commented out “Write-Host” lines that you can uncomment for debugging purposes.

The code:

"Find and Update Content Editor Web Parts loaded..." 

"Run using:"
"  Get-SPWebPartsForWeb  yourURL         (for a single site)"
"  Get-SPWebPartsForSite  yourURL        (for all sites in a site collection)"
"  Get-SPWebPartsForApplication  yourURL (for all site collections in an app)" 

#  Change these two variables
$textToFind = "theBeforeText"
$newText    = "theAfterText" 

$librariesToCheck = "Site Pages","SitePages","Pages"
$checkrootdefaultaspx = $true 

function Check-Page($page)
{
        # borrow a .NET method GetExtension
        if ([system.io.path]::GetExtension($page.url).ToLower() -ne ".aspx")
        {
          continue #not a webpart page, so back to the foreach
        } 

        # try and get the WebPartManager for the page
        $wpm = $null
        try
        {
          $wpm = $page.GetLimitedWebPartManager([System.Web.UI.WebControls.Webparts.PersonalizationScope]::Shared)
        #"    Webparts: " + $wpm.webparts.count
        }
        catch
        {
          #"   Not a web part page"
        } 

        if ($wpm -ne $null)  # then we have a webpart page
        {
          Write-Host "    Page: " $page.Url 

          # report each web part found
          foreach ($webpart in $wpm.webparts)
          { 

            Write-Host "      Web part: " $webpart.WebBrowsableObject.ToString().Replace("Microsoft.SharePoint.","") -foregroundcolor blue
            Write-Host "         Title: " $webpart.Title
            if ( $webpart.WebBrowsableObject.ToString() -eq "Microsoft.SharePoint.WebPartPages.ContentEditorWebPart" )
            { 

              # if there's linked content then open and search for the script tag
              if  ($webpart.contentlink.length -gt 0 )
              {
                $file = $w.GetFile($webpart.contentlink)
                $b = $file.OpenBinary()
                $encoding=new-object "System.Text.UTF7Encoding"
                if ($encoding.GetString($b).toLower() -match "<script")
                {
                  Write-Host "         contentlink: HAS <SCRIPT>" $webpart.contentlink -foregroundcolor red
                }
                Remove-Variable b
              } 

              # else report what's in the content
              elseif ($webpart.content."#cdata-section".tolower() -match "<script")
                {
                  Write-Host "         content: HAS <SCRIPT>"  -foregroundcolor red 

# write-host $webpart.content."#cdata-section" -foregroundcolor green 

$xmlDoc = New-Object -TypeName xml
$xmlElement = $xmlDoc.CreateElement("MyElement"); 

# THIS IS WHERE THE REPLACE IS DONE.
$xmlElement.InnerText = $webpart.Content.InnerText.Replace($textToFind, $newText); 

$webpart.content = $xmlElement 

$wpm.savechanges($webpart) 

                }
            } 

          }
        } 

} 

filter Get-WebPartPages
{
  # this filter accepts a SPWeb and returns SPPages from target libraries 

# write-host "getting webparts"
  $w = $_
  #Write-Host ""
  #Write-Host "Web: "  $w.ServerRelativeUrl #-foregroundcolor yellow 

  if ($checkrootdefaultaspx)
  {
    #Write-Host "  Root: default.aspx"
    foreach ($file in $w.files)
    {
      if ($file.url -eq "default.aspx")
      {
        $file
      } 
    }
  }
  # Write-Host "now for lists..................." $w.lists.count
  foreach ($list in $w.Lists)
  {
      #Write-Host "  List: " $list.title $librariesToCheck $("'" + $list.title + "'")
    if ( $librariesToCheck -like "*'$($list.title)'*" )
    {
      #Write-Host "File name " -ForegroundColor red
      foreach ($item in $list.items)
      {
        #Write-Host "File name " $item.file.url -ForegroundColor red
        $page = $item.file 

        $page
      }
    }
  }
} 

function Check-WebParts($w)
{ 

  Write-Host ""
  Write-Host "Web: "  $w.ServerRelativeUrl -foregroundcolor yellow 

  if ($checkrootdefaultaspx)
  {
    Write-Host "  Root: "
    foreach ($file in $w.files)
    {
      if ($file.url -eq "default.aspx")
      {
        Check-Page($file)
      } 
    }
  } 

  foreach ($list in $w.Lists)
  {
  Write-Host ("'" + $list.title + "'")
    if ( $librariesToCheck -contains $list.title )
    {
      write-host $list.title
      foreach ($item in $list.items)
      {
        $page = $item.file 

        Check-Page($page)
      }
    }
  } 

} 

Function Get-SPWebPartsForWeb($url)
{
  $web = Get-SPWeb($url)
  Check-WebParts($web)
  $web.Dispose()
} 

Function Get-SPWebPartsForSite($url)
{
  $site = Get-SPSite($url)
  foreach($web in $site.AllWebs)
  {
    Check-WebParts($web)
    $web.Dispose()
  }
  $site.Dispose()
} 

Function Get-SPWebPartsForApplication($url)
{
  $app = Get-SPWebApplication($url)
  foreach ($site in $app.sites)
  {
    foreach($web in $site.AllWebs)
    {
      Check-WebParts($web)
      $web.Dispose()
    }
    $site.Dispose()
  }
}

 

.

Note to spammers!

Spammers, don't waste your time... all posts are moderated. If your comment includes unrelated links, is advertising, or just pure spam, it will never be seen.