Showing posts with label Sharepoint foundation 2010. Show all posts
Showing posts with label Sharepoint foundation 2010. Show all posts

Wednesday, October 14, 2015

Create mysite using Powershell

Function Create-MySite           
{           
 [CmdletBinding()]           
 Param           
 (           
  [Parameter(Mandatory = $True,Position=2,valueFromPipeline=$true)][String]$Username,           
     [Parameter(Mandatory = $True,Position=1)][String]$MySiteRootURL             
 )           
 [void][reflection.assembly]::Loadwithpartialname("Microsoft.Office.Server");              
 $site=new-object Microsoft.SharePoint.SPSite($MySiteRootURL);           
 try           
 {           
  $serviceContext = Get-SPServiceContext $site;           
  $upm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext);            
  if($upm.UserExists($Username) -eq $false)           
  {           
   Write-Host "User $Username was not found in the profile store." -f yellow;           
   return;           
  }           
  $userProfile = $upm.GetUserProfile($Username);           
  if($userProfile.PersonalSite -eq $Null)           
  {           
   Write-Host "Creating MySite for user $Username" -f darkyellow;           
   $userProfile.CreatePersonalSite();                 
   Write-host "Successfully created MySite for user $Username" -f green;           
  }           
  else           
  {           
   Write-Host "User $Username already has a MySite." -f darkgreen;           
  }           
 }           
 catch           
 {           
  Write-Host "Encountered an error creating a MySite for user $Username. Error:"$_.Exception -f Red;           
 }           
 finally           
 {           
  $site.Dispose();           
 }           
}
Create-MySite -MySiteRootURL "http://url" -Username "domain\user"

Friday, October 9, 2015

Powershell script remove contenttypes from list


#Get site object and specify name of the library to look for in each site
$site = Get-SPSite http://URL
$lookForList = "ListName"
$ContentType = "CTName"
#Walk through each site and change content types on the list specified
$site | Get-SPWeb -Limit all | ForEach-Object {

write-host "Checking site:"$_.Title

#Check list exists
$docLibrary = $_.Lists[$lookForList]

#Remove unwanted content types from the list
if($docLibrary -ne $null)
{
$ctToRemove = $docLibrary.ContentTypes[$ContentType]
write-host "Removing content type" $ctToRemove.Name "from list" $docLibrary.Title
$docLibrary.ContentTypes.Delete($ctToRemove.Id)
$docLibrary.Update()
}
else
{
write-host "The list" $lookForList "does not exist in site" $_.Title
}
}
#Dispose of the site object
$site.Dispose()

Thursday, June 11, 2015

Export managed metadata

Get-SpServiceApplication | select DisplayName, ID
Get-SPServiceApplicationProxy | select DisplayName, ID
$mmsAppId = "GUID"
$mmsproxy = Get-SPServiceApplicationProxy -Identity GUID
Export-SPMetadataWebServicePartitionData -Identity $mmsAppId -ServiceProxy $mmsproxy -Path \\server\path\filename.bak

Migrate SharePoint social tag comments

Add-PSSnapin microsoft.sharepoint.powershell

$upaProxy = Get-SPServiceApplicationProxy GUID

$site = get-spsite #URL

$listName = #LISTNAME

foreach($web in $site.AllWebs){



$oldurl = ""

$newurl = ""

if($web.ParentWeb.Url -eq $site.url){



$list = $web.Lists[$listName]

$items = $list.items



foreach($item in $items)

{

if($item.xml -Like "*#RELPATH/PAGE.aspx, PAGETYPE*"){



$newurl = $web.url + "/" + $item.url

[System.uri]$newurl = $newurl

$newurl.AbsoluteUri



$oldurl = $newurl.AbsoluteUri

$oldurl = $oldurl -replace "SITE1", "SITE2"

$oldurl



Move-SPSocialComments -ProfileServiceApplicationProxy $upaProxy -OldUrl $oldurl -NewUrl $newurl.AbsoluteUri



}

}

}

}


Monday, July 7, 2014

Security Token Service is down or showing errors?



Some examples of errors that may show up in your ULS log.


Run the following commands, it will do a new provisioning of the Security Token Service.

$h = Get-SPServiceHostconfig
$h.Provision()
$services = Get-SPServiceApplication
foreach ($service in $services) { $service.provision();
write-host $service.name}


Perform an IIS Reset and try to browse the STS, http://localhost:32843/SecurityTokenServiceApplication/securitytoken.svc

Wednesday, August 28, 2013

Count of all Documents in SharePoint 2010 Farm with Powershell


Get-SPSite -Limit All | Get-SPWeb -Limit All | % { $_.Lists} | ? { $_ -is [Microsoft.SharePoint.SPDocumentLibrary] } | % { $total+= $_.ItemCount} ; $total

Thursday, May 2, 2013

Open PDF

$webApp = Get-SPWebApplication http://url
If ($webApp.AllowedInlineDownloadedMimeTypes -notcontains "application/pdf")
{
  Write-Host "Adding PDF MIME Type..."
  $webApp.AllowedInlineDownloadedMimeTypes.Add("application/pdf")
  $webApp.Update()
  Write-Host "MIME Type saved."
} Else {
  Write-Host -ForegroundColor red "PDF MIME type is already added."
}

Thursday, April 18, 2013

Fucked up timer job?

Update userinfo from Active Directory to Site Collection, if timer job is fucked up.

get-spuser -Web http://url -Identity domain\user
set-spuser -Web http://url -Identity domain\user -SyncFromAD

Wednesday, March 20, 2013

Import photos from AD to SharePoint 2010

This is a time comsuming feature, here's the step for doing it right and saving time and insanity... :)

PreReq
User Profile Service application
MySite
Walkthrough
At present there is no picture associated to this user inside Active Directory.
image
Note- You will not see all the user attributes if you have not turned on the “Advanced Features”. You can also view the same information from ADSI.

How to import Pictures
Now our Goal is to import the user profile along with his picture, we will also upload his picture in AD.
1) First we need to make sure we are able to import users. So I will create connection to OU – PictureOU and import users
image
Note- I am only importing users from OU PictureOU
2) Let’s check user’s profile in SharePoint and make sure there is no picture associated to it.
image

Picture for this user is set to be blank
3) Upload Pictures to Active Directory.
Lots of people also have trouble in finding out ways to upload pictures in Active Directory. Following are the two best methods that I am aware off
A. Run these commands in Windows Powershell. We need to have Windows Administrative tools loaded for this to work
Import-Module ActiveDirectory
$photo=[byte[]](Get-Content C:\photo.jpg -Encoding byte)
Set-ADUser "username" -Replace @{thumbnailPhoto=$photo}
4) Let’s check User properties in Active Directory and make sure if has Picture value set
image

5) Map the Picture property to Thumnail Photo
A) Browse to User Profile Service Application from Central Administration and then click on Manage User Properties
Central Administration > UPA > Manage User Properties
B) Click on Picture and then Edit
image
C) We need to Map this to Attribute “thumnailPhoto” and Select Import from the Direction. Make sure you click on on Add
image
D) After clicking on Add make sure it shows up under the “Property Mapping for Synchronization”section
image
E) Click on OK
6) Start incremental Import
7) Let’s check the User properties and see if the image has been populated
image
So Picture still showing blank
8) Let’s check MIIS client and see if it made an attempt to import the picture. For this we will need to DS_DELTASYNC
image
So it does appear that FIM picked up the image successfully from Active Directory
9) Let’s check the Sync DB by running the following query
Select sAMAccountName,SPS_MV_OctetString_PictureURL from MMS_Metaverse with(nolock) Where SAMAccountName like '%UserName%'
image
So it appears Sync DB has successfully got updated with the Image.

10) Now let’s check the Profile DB by running the following query
Select NTname,PictureURL from UserProfile_full with(nolock) where NTName like ‘%harmeet%’
image
So it appears that Picture has not made it to the Profile DB
11) Run the following in SharePoint Management Shell
Update-SPProfilePhotoStore -CreateThumbnailsForImportedPhotos 1 -MySiteHostLocation http://mysite

http://support.microsoft.com/kb/2394320
12) Now if you go back to the user profile you will see that the image has been updated

Pre-create my site

How to create my site in SharePoint 2010 by powershell or STSADM?
  1. Use the following deprecated STSADM command:
    STSADM -o createsite see also http://technet.microsoft.com/en-us/library/cc262594(office.12).aspx
    (for MySite use SPSPERS#0 for the site template)
  2. Or Use the following Powershell script:
    Get-SPWebTemplate
    $template = Get-SPWebTemplate "SPSPERS#0"
    New-SPSite -Url "<URL for the new site collection>" -OwnerAlias "<domain\user>" -Template $template
    see also http://technet.microsoft.com/en-us/library/cc263094.aspx

Tuesday, January 22, 2013

How to find Apppools username AND password?

At your WFE, C:\Windows\System32\inetsrv>
type appcmd list apppool /text:*

This will bring up a list of every applicationpools at your WFE, showing both Username and Password! Helpful if you have lost any password, but also a possible security issue, everyone having access to your WFE and have administration rights can also gain access to your accounts and password. What about you have accounts with Active Directory permissions?

Wednesday, October 10, 2012

Powershell script sync Sharepoint user from AD


Powershell script sync Sharepoint user from AD

get-spuser -identity domain\user -web url
set-spuser -identity domain\user -SyncFromAD -web url