Pre-provision MySite user site via script?

1,916

This should get you started - you'll need to wrap the site creation part in a loop over your user list and possibly add some more error checking.

I know for sure this works in 2007 but haven't tested it in 2010. All the same stuff exists so it should. One final thing - this is SLOW - creating 1 user on my SP2007 server takes 5-10 seconds. If your mysites farm is beefy enough, you might actually be better off letting the users create their personal sites ad-hoc.

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

$siteurl = "http://your.mysitesurl.com"    

$site = New-Object Microsoft.SharePoint.SPSite($siteurl)
$context = [Microsoft.Office.Server.ServerContext]::GetContext($site)
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)

# start loop here
$user = "domain\username"
if ($upm.UserExists($user)) {
    $profile = $upm.GetUserProfile($user)

    # there are other exceptions you can catch, check out the UserProfiles class
    trap [Microsoft.Office.Server.UserProfiles.PersonalSiteExistsException] {
            Write-Host "personal site already exists for $user"
            continue
    }
    $profile.CreatePersonalSite();
}  else {
  Write-Host: "user $user did not exist"
}
# end loop here

$site.Dispose()
Share:
1,916

Related videos on Youtube

Huza
Author by

Huza

Updated on September 17, 2022

Comments

  • Huza
    Huza over 1 year

    On the left we have a context sensitive navigation/information bar. At times there is very little information in it and other times it takes up the entire height of the page. I've seen a bunch of suggestions on other posts about floating, etc but nothing I've tried works.

    .tablebox {float:left;position:relative;z-index:1;border-right:1px solid #000000;}
    .groupbox {float:left;position:relative;z-index:-1;border-right:1px solid #000000;}
    

    So two divs for the sidebar - one to create the background layer which will take up the entire height of the page and then tablebox with the actual content on it - it could have a different background color as required.

    <div class="tablebox" style="margin-top:5px;width:247px;">Sidebar</div>
    <div class="groupbox" style="width:247px;background-color:#FFFFFF;top:120px;bottom:0;left:0px;"></div>
    

    Then we have the right hand side main content... again the idea being that tablebox would have a different background colour and appear to float on top of the page.

    <div class="tablebox" style="margin-top:5px;width:777px;">Main content</div>
    <div class="groupbox" style="width:777px;top:120px;bottom:0;left:247px;"></div>
    

    Now if the browser width gets to be too small the right hand div falls below the sidebar. Whether there's room there or not.

    SOLUTION: The problem was that the two sets of divs's parent did not have a defined size. As the browser window was resized the children got shuffled to fit inside of the new size. By defining a parent div with a fixed width and adding a overflow:auto the parent would not change even if the browser window was.

    Note: This is not the best way to resolve this obviously - this means that the content does not dynamically format itself. It now has a fixed width. In my case I have no other choice. It is a band aid solution but if you're in the design stage think about people viewing your page from a cellphone or old people with their low resolution screens and giant text.

    To be clear for those easily confused:

    <div style="width:1053px;overflow:auto">
    <div class="tablebox" style="margin-top:5px;width:247px;">Sidebar</div>
    <div class="groupbox" style="width:247px;background-color:#FFFFFF;top:120px;bottom:0;left:0px;"></div>
    <div class="tablebox" style="margin-top:5px;width:777px;">Main content</div>
    <div class="groupbox" style="width:777px;top:120px;bottom:0;left:247px;"></div>
    </div>
    

    But again - if you have a choice don't do this! Fixed width will not make your site very pretty on some devices.

    • Garry Cairns
      Garry Cairns about 11 years
      Please consider using a frontend framework such as Twitter bootstrap instead of hand coding css from scratch. It really does save a lot of pain.
    • Huza
      Huza about 11 years
      Sadly this is integrating into an existing php project. The ui and the backend are not separate. That would make my life much easier. I'm trying to see if there's a simple answer before I rewrite a ton of code. I'll take a look though. Thanks for the suggestion!
    • Garry Cairns
      Garry Cairns about 11 years
      Yikes, you have my sympathy and best wishes.
  • Chris W
    Chris W almost 14 years
    Thanks this is great. I expect the creation to be slow but we have the benefit of a window in the summer when we can set up any new students before they arrive by running this over a few nights if we need to. You've been a big help on this and most of my SharePoint questions!
  • Anthony Graglia
    Anthony Graglia about 13 years
    @Chris, Did this work?
  • Chris W
    Chris W about 13 years
    Didn't end up using it - the rollout ended up being phased enough that we didn't need to worry about too many people all hitting it at once.
  • Patt Mehta
    Patt Mehta about 11 years
    @Huza: First try the above code in an html file, you will get the answer to your question
  • Patt Mehta
    Patt Mehta about 11 years
    Please try to use percentages instead of px because that will make your web applications responsive and not only the movements while resizing be fluid but they will be free of javascript etc, otherwise even I am redsgning my website using bootstrap for rapid deployment
  • Huza
    Huza about 11 years
    Yes - setting up percentages and better support for all is on my to-do list. Sadly there are higher priorities right now.
  • Patt Mehta
    Patt Mehta about 11 years
    same here, I want to transform but I can't, but in the answer I am hinting to use float:right that's all :D plz upvote if you find it the correct solution to your problem