Retrieving user email using powershell/web services
-
Monday, March 12, 2012 5:48 PM
I am using powershell (on a non SharePoint server, so I don't have access to the SharePoint snapins) to read a SharePoint list through the SharePoint WebServices lists.asmx functionality and want to email the person in one of the people fields via the Net.Mail.SmtpClient
The people field only gives me the id and the user's display name. How do I get the email address?
I'm constrained by the environment I'm running on.
I can't use SharePoint functionality except through the generic web services (which works just fine - I can successfully read the list, pick up the people field, and get the ID and the display name by splitting it apart.)
SMTP email.send needs an account name or an email address. I only have the display name.I've tried the user profile webservices but can't seem to get those to work.
I've tried using the lists.asmx service to read the User Profile Information list but that's not working - not sure if it's a security problem or not.I don't seem to have any AD providers available - is that what I need to use?
Robin
All Replies
-
Tuesday, March 13, 2012 2:17 PM
You can use powershell and the UserGroup webservice to retrieve the e-mail address of a SharePoint user:
$WebUrl = "http://SharePoint/Subsite" $SPService = New-WebServiceProxy -Uri ($WebUrl + "/_vti_bin/UserGroup.asmx?WDSL") -UseDefaultCredential $SPService.Url = $WebUrl + "/_vti_bin/UserGroup.asmx?WDSL" $User = $SPService.GetUserInfo("DOMAIN\USER").User; $User.Email
- Edited by Alain de Klerk Tuesday, March 13, 2012 2:21 PM
-
Tuesday, March 13, 2012 5:29 PMThanks for the code, I was never sure of the structure. Problem is ;) I don't have the DOMAIN\USER to pass to the service, I only have the display name and the user ID number (assuming that's for the User Information List). I need some magic to get the account name, then I could use your code. I can't seem to get to the User Information List - not sure if it's a security problem or what. I was expecting to get to the UIL with the user id number to get the account name, which would be good enough to pass on to the smtp send method.
Robin
-
Wednesday, March 14, 2012 3:59 PM
In that case, use the GetAllUserCollectionFromWeb web-method and filter by UserDisplayName of UserID
$WebUrl = "http://SharePoint/Subsite" $SPService = New-WebServiceProxy -Uri ($WebUrl + "/_vti_bin/UserGroup.asmx?WDSL") -UseDefaultCredential $SPService.Url = $WebUrl + "/_vti_bin/UserGroup.asmx?WDSL" $Users = $SPService.GetAllUserCollectionFromWeb().Users #$Users.User | Where-Object {$_.Name -eq 'User Display Name' } | Select-Object Email $Users.User | Where-Object {$_.ID -eq 'SP User ID' } | Select-Object Email
- Edited by Alain de Klerk Wednesday, March 14, 2012 4:06 PM
- Marked As Answer by Robin In OR Wednesday, March 14, 2012 4:08 PM
-
Wednesday, March 14, 2012 4:08 PMPerfect! Didn't even think of going more generic with looking at all users. Thanks, you've simplified my day.
Robin

