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)
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:
- Click the Data Tab > Data Connections > Add
- Select Create a new connection to: Recieve data, click Next
- Select Soap Web Service, click Next
- 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.
- Choose GetUserProfileByName, click Next, Next, Next
- 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.
- Click the Home Tab then under controls double click the Person/Group picker to add it to the form.
- 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
- right click DisplayName> click properties > then click the ƒx button under default value
- click Insert Field or Group, Then from the drop down select the new data connection you created (GetuserProfileByName)
- Expand the dataFields node all the way down through to the values node (see below) and highlight “Value”
- with the “Value” field highlighted click Filter Data…
- Once the Filter Data window pops up click add… to add a new filter to specify the filter conditions
- 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
- For the condition make sure it is set to “is equal to”
- for the second value choose type Text and put “PreferredName” and hit ok, ok, ok, ok, ok.
- Next you will need to do a simlar thing for the people picker AccountId field (Repeat steps 3-9)
- 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
- Finally the last field you need to populate is the AccountType. This one you only need to set the default value to “User”.
- 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.