Using PowerShell ISE with SharePoint

PowerShell ISE is a great tool for editing PowerShell scripts however by default it does not have access to any of the SharePoint cmdlets. If you add the following lines at the top of your scripts in ISE (or run in ISE prior to making your scripts) you will get full access to SharePoint cmdlets:


#Load the SharePoint Powershell snapin

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
{
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}

Advertisements

Auto Populate InfoPath People Pickers

There are plenty of times in which you will want users to pick a person from a people picker for your forms however it is not immediately apparent how to have a people picker field auto populated with the user who’s opening the form. I thought I would give an example of this.

First it is assumed that you will be creating a browser enabled form for SharePoint 2010. This still works for regular forms however you need the SharePoint environment available.

I’ll start by creating a data connection to the SharePoint UserProfile web service:

  1. Click the Data Tab > Data Connections > Add
  2. Select Create a new connection to: Recieve data, click Next
  3. Select Soap Web Service, click Next
  4. Enter http://<Your Site>/_vti_bin/UserProfileService.asmx, click Next. see http://msdn.microsoft.com/en-us/library/ee705814.aspx for a listing of available SharePoint 2010 web services.
  5. Choose GetUserProfileByName, click Next, Next, Next
  6. Name the data connection to something useful to remember GetUserProfileByName is Default, then click Finish

Now that we have our data connection set up, now its time to add the people picker.

  1. Click the Home Tab then under controls double click the Person/Group picker to add it to the form.
  2. You’ll notice in the fields section that a people picker is in fact a group with 3 fields in it. (if you don’t have the fields section open this can be done by going to the data tab > show fields)

    Next we need to set default values to these fields
  3. right click DisplayName> click properties > then click the ƒx button under default value
  4. click Insert Field or Group, Then from the drop down select the new data connection you created (GetuserProfileByName)
  5. Expand the dataFields node all the way down through to the values node (see below) and highlight “Value”
  6. with the “Value” field highlighted click Filter Data…
  7. Once the Filter Data window pops up click add… to add a new filter to specify the filter conditions
  8. For the first value of the filter conditions select “Select a field or group…” and then choose Name of your GetUserProfileByName Data Source and hit ok
  9. For the condition make sure it is set to “is equal to”
  10. for the second value choose type Text and put “PreferredName” and hit ok, ok, ok, ok, ok.
  11. Next you will need to do a simlar thing for the people picker AccountId field (Repeat steps 3-9)
  12. for the second value, this time choose type Text and put “AccountName”. For a listing of what properties are available by the GetUserProfileByName Webservice check out Martin’s Blog: http://www.martinsvendsen.com/2009/01/getuserprofilebyname-profile-properties.html
  13. Finally the last field you need to populate is the AccountType. This one you only need to set the default value to “User”.
  14. You can verify that it works by previewing the form before uploading to SharePoint. Remember for people pickers you need to specify the SharePoint Server in the properties section by right clicking the “Person/Group Picker”

Now you can autopopulate the people picker field when someone opens the form. Remember if you want the people picker to retain the information of the first user who opened the form uncheck the “Refresh value when formula is recalculated” box of the DisplayName and AccountId field properties.