I've managed to import user profiles from our AD. Now I want to add all the imported user profiles into a specific SharePoint group, let's say Visitors, and doing this by using the People Picker takes ages. So I was wondering if there was a way of doing this by using Powershell? It would also be nice if the script could run like once a day so that any newly imported user profiles would get added to the group aswell, this can be done thru a timer job right?

Update: I ran the script again after editing $User = $OpenWeb.Users to $User = $OpenWeb.SiteUsers (before that I only got one profile and that was the one was I was logged in as) and this time it semi-worked but the only users that was added to the group were users already added to other groups, not all the users from the user profile database (I'm guessing from the SyncDB?). I can find them if I search for specific profiles in CA -> Manage Service Applications -> User Profile Service Application -> Manage User Profiles, so I know that they are there. Do I have to edit the script in some way in order to get the profiles from the SyncDB (which is where I'm guessing that they are stored)?


1 Answer 1


The powershell script should be like this:

$SPSite = New-Object Microsoft.SharePoint.SPSite("http://wss"); 
$OpenWeb = $SpSite.OpenWeb(); 
$TheNewGroup = $OpenWeb.SiteGroups | Where-Object {$_.Name -match "The New Group"}; 

$SPSite = New-Object Microsoft.SharePoint.SPSite("http://wss"); 
$OpenWeb = $SpSite.OpenWeb(); 
$User = $OpenWeb.Users | Select Name, Email, LoginName; 

$User | ForEach-Object {

Ok, so it is possible to add powershell to a timerjob, see link below (from tarjeieo).

  • 1
    It's possible alright; ikarstein.wordpress.com/2011/08/04/…
    – tarjeieo
    Oct 25, 2011 at 8:13
  • Please dont just link to external content. We like to keep all the good stuff in our site -external sites often tend to have a short life span... Post relevant facts in answer and then link to source please Oct 25, 2011 at 8:21
  • 1
    you can also just create a Schedule on your application server that calls either PowerShell directly or through a cmd/batch file calls PowerShell and the appropriate .ps1 file Oct 25, 2011 at 8:38
  • Follow-up question to the script above: if I wanted to get all the user properties do I just need to remove the Select at $User or do I have to add all the properties I want imported?
    – K.W
    Oct 25, 2011 at 11:55
  • you could omit the whole | select... part. Then you would receive SPUser objects. Alternatively select the ones you need or * Oct 25, 2011 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.