使用 Powershell 启用 Sharepoint 功能

发布于 2024-11-28 11:33:25 字数 1810 浏览 0 评论 0原文

我是 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;

I am new to PowerShell and have been asked to modify a script that is used to activate features on a site. The script has some latency issues between the two feature activations, so I decided to make a new function that will enable the feature and sleep or delay until the feature is finished enabling. Will this work? And if so, how can I tell that the feature is finished activating?

# 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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感性 2024-12-05 11:33:25
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.."
}

}

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.."
}

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文