首页 > 代码库 > Powershell配置SharePoint环境(再续)

Powershell配置SharePoint环境(再续)


1. 给用户在User Profile Service Application中赋权:


$accountName = "contoso\testuser"

$claimType ="http://schemas.microsoft.com/sharepoint/2009/08/claims/userlogonname"

$claimValue = http://www.mamicode.com/$accountName

$claim = New-Object Microsoft.SharePoint.Administration.Claims.SPClaim($claimType,$claimValue, "http://www.w3.org/2001/XMLSchema#string",[Microsoft.SharePoint.Administration.Claims.SPOriginalIssuers]::Format("Windows"))

$claim.ToEncodedString()

$permission = [Microsoft.SharePoint.Administration.AccessControl.SPIisWebServiceApplicationRights]"FullControl"

$SPAclAccessRule =[Type]"Microsoft.SharePoint.Administration.AccessControl.SPAclAccessRule``1"

$specificSPAclAccessRule =$SPAclAccessRule.MakeGenericType([Type]"Microsoft.SharePoint.Administration.AccessControl.SPIisWebServiceApplicationRights")

$ctor =$SpecificSPAclAccessRule.GetConstructor(@([Type]"Microsoft.SharePoint.Administration.Claims.SPClaim",[Type]"Microsoft.SharePoint.Administration.AccessControl.SPIisWebServiceApplicationRights"))

$accessRule =$ctor.Invoke(@([Microsoft.SharePoint.Administration.Claims.SPClaim]$claim,$permission))

$ups = Get-SPServiceApplication| ? { $_.TypeName -eq ‘User Profile Service Application‘ }

$accessControl =$ups.GetAccessControl()

$accessControl.AddAccessRule($accessRule)

$ups.SetAccessControl($accessControl)

$ups.Update()


2. 启动SharePoint场中所有的Timer Service:


       $spFarm=Get-SPFarm

       $spfTimerServcicesInstance=$spFarm.TimerService.Instances

       foreach($spfTimerServiceInstance in $spfTimerServcicesInstances)

       {

            Write-Host"Re-starting the instance " $spfTimerServiceInstance.TypeName

           $spfTimerServiceInstance.Stop()

           $spfTimerServiceInstance.Start()

        }


3. 备份SharePoint场中的solution:


New-Item $FolderPath\$FolderName -ItemType Directory -Force 

Set-Location$FolderPath\$FolderName

(Get-SPFarm).Solutions | %{$Solutions =(Get-Location).Path + “\” + $_.Name; $_.SolutionFile.SaveAs($Solutions)}  





Powershell配置SharePoint环境(再续)