Solved

SharePoint 2010 powershell script help

Posted on 2014-07-21
8
662 Views
Last Modified: 2014-07-25
With regards to SharePoint 2010 we are testing out the ability to import AD account pictures into SharePoint.
I'm able to do a full profile import to get the users picture into our Mysite picture library. It will create 1 picture with a cryptic file name. Then I'll go into the "SharePoint 2010 management shell" and select the link to "Run as Administrator".
I run the below command which completes successfully:
Update-SPProfilePhotoStore -CreateThumbnailsForImportedPhotos 1 -MySiteHostLocation http://mysite
I then see the 3 different sized profile pics for the user that was imported.

Now I need to automate this and I am not familar with PowerShell. This is where I could use some help.

Ideally, I want to write a powershell script which calls the command and if there were errors/warnings running the command, create a notification. At the least though I just want to get the command working. I'm familar with programming and various languages so I just need some help starting off.

I'm testing in a development server. I've created a ps1 file with the command:
Update-SPProfilePhotoStore -CreateThumbnailsForImportedPhotos 1 -MySiteHostLocation http://mysite

1) How can I get the result of the command including verbage that the command produces using PowerShell.
2) When I go through the Windows OS GUI and select SharePoint 2010 management shell and than Run as Administrator
    is there code I need to add to the ps1 file to mimic this. I am running it right now while logged in as an account that has
    the ability to execute this command. I just can't seem to get it to run when I do it via a script verses typing it into the
    command line. Not seeing results of the command does help so that is where (1) comes in.

Can someone give me a hand. I've seen different things on the internet and I think I'm missing a key detail though.
I just need to get over this hump starting off.

Thanks.
0
Comment
Question by:PSSupport
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 15

Accepted Solution

by:
colly92002 earned 50 total points
ID: 40212863
Can I assume that you are you trying to do this via the task scheduler?  IF so follow this guide:
http://get-spscripts.com/2011/01/running-sharepoint-powershell-script.html

This explains how to configure the task scheduler to run a SharePoint PS command.  IT should do everything you need.

A more generic look at scheduling PS can be found here:
http://dmitrysotnikov.wordpress.com/2011/02/03/how-to-schedule-a-powershell-script/
0
 
LVL 38

Expert Comment

by:Justin Smith
ID: 40214959
Use the Start-Transcript command to spit out everything to a text file.
0
 
LVL 38

Assisted Solution

by:Justin Smith
Justin Smith earned 20 total points
ID: 40214966
Also, at the beginning of your script you should import the SharePoint module. Something like

if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PSSnapin Microsoft.SharePoint.Powershell
}
0
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
LVL 8

Assisted Solution

by:Jayaraja Jayaraman
Jayaraja Jayaraman earned 30 total points
ID: 40217973
$ssite=get-spsite "Site Url"
$sweb=$ssite.openweb("WebName")
$slist=$sweb.lists["Employee Pictures"]
write-host $slist.itemcount
foreach($item in $slist.items)
{
$nwid=$item["NetworkID"]
$usid='awacgbl\'+$nwid
write-host $item["NetworkID"]   $usid
$item["User_x0020_Name"]=New-SPUser –UserAlias $usid –Web $sweb
write-host $item["User_x0020_Name"]
$item.SystemUpdate()
}

or

$siteUrl="SiteUrl"
$upm = GetProfileManager -url $siteUrl
$up = $upm.GetUserProfile("domainname\comurphy");

$picturePropertyName = GetProfilePropertyName -UserProfileManager $upm -PropertyName "PictureUrl";

if (-not [System.String]::IsNullOrEmpty($picturePropertyName))
{
    $PortraitUrl = CombineUrls -baseUrl $file.Web.Url -relUrl $file.ServerRelativeUrl;
    $up.get_Item($picturePropertyName).Value = $PortraitUrl;
}
0
 
LVL 38

Expert Comment

by:Justin Smith
ID: 40218458
jayaraja your response doesn't help or answer any part of the question.  If you ran your code from a powershell session it would fail as you didn't import the SharePoint snap-in.
0
 
LVL 1

Author Comment

by:PSSupport
ID: 40219848
Thanks colly92002 and ACH1LLES . the Add-PSSnapin was the missing piece that I needed for the puzzle. I can now test the SP Ad import command from the script so I can move forward with this. The Transcript command is also a good thing to know.
0
 
LVL 1

Author Closing Comment

by:PSSupport
ID: 40219856
I had specfic questions which I would have like to be addressed directly from expert exchange. I can find links on the net as well. Sometimes though its key info I need to help me jog my searches online to fine tune them. But you guys did help me. Thanks.
0
 
LVL 8

Expert Comment

by:Jayaraja Jayaraman
ID: 40220126
@ACH1LLES - please note tat its understable by people who are working with sp for atleast couple of years to know to run the sharepoint related powershell commands from sharepoint powershell console where in you dont need to add the pssnapin.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A procedure for exporting installed hotfix details of remote computers using powershell
In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question