【问题标题】:Enabling Sharepoint Features With Powershell使用 Powershell 启用 Sharepoint 功能
【发布时间】:2013-04-10 16:37:14
【问题描述】:

我是 PowerShell 新手,我被要求修改用于激活网站功能的脚本。该脚本在两个功能激活之间存在一些延迟问题,因此我决定制作一个新功能,该功能将启用该功能并休眠或延迟,直到该功能完成启用。这行得通吗?如果是这样,我如何判断该功能已完成激活?

# This is a function that enable's a Sharepoint Feature and Sleeps Until Its Finished Enabling

function Feature-Enable

{param ([string]$ID, [string]$URL)

#Enable Feature

Enable-SPFeature -Identity $ID -url $URL -Confirm:$false

#Sleep Until Feature is Done Enabling

}

#Set parameters/variables for script
$serverName = "someServerName"
$rootwebUrl = "someRootUrl"

$currentpath=Split-Path -Path $MyInvocation.MyCommand.Path -Parent

$siteURL = "http://" + $servername + $rootwebURL

$start = Get-Date -DisplayHint Time

# check to ensure Microsoft.SharePoint.PowerShell is loaded

$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}

if ($snapin -eq $null) {

Write-Host "Loading SharePoint Powershell Snapin"

Add-PSSnapin "Microsoft.SharePoint.Powershell"

}


#         Active Site Collection Features (in order)

        write-host ""

        write-host "----------------------------------------"

        write-host "Begin activation of site collection features"

        write-host "----------------------------------------"

        write-host ""

  Feature-Enable –identity "3cbf5d1e-ff2e-48d2-82a4-99b060381268" -URL $siteUrl


#NOTE:  POTENTIAL LATENCY ISSUES.   MAY NEED TO INSERT DELAY TIMER!

  Feature-Enable –identity "bbde524e-9293-468e-84f7-fdb763ffa309" -URL $siteUrl

        write-host ""

        write-host "----------------------------------------"

        write-host "Activation of site collection features - DONE!"

        write-host "----------------------------------------"

        write-host ""


$end= Get-Date -DisplayHint Time

Write-Host "Started at: " $start " Ended at:  " $end;

【问题讨论】:

    标签: sharepoint powershell


    【解决方案1】:
    function WaitForJobToFinish([string]$SolutionFileName)
    { 
        $JobName = "*solution-deployment*$SolutionFileName*"
        $job = Get-SPTimerJob | ?{ $_.Name -like $JobName }
        if ($job -eq $null) 
    {
        Write-Host 'Timer job not found'
    }
    else
    {
        $JobFullName = $job.Name
        Write-Host -NoNewLine "Waiting to finish job $JobFullName"
    
        while ((Get-SPTimerJob $JobFullName) -ne $null) 
        {
            Write-Host -NoNewLine .
            Start-Sleep -Seconds 2
        }
        Write-Host  "Finished waiting for job.."
    }
    

    }

    【讨论】:

      猜你喜欢
      • 2013-09-13
      • 2017-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-08
      • 2015-01-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多