使用SharePoint 2013中的PowerShell激活WebApplication Scoped功能(管理Web应用程序功能下的自定义支持) [英] Activate the WebApplication Scoped Features(Custom fearute under manage webapplication features) using PowerShell in SharePoint 2013

查看:49
本文介绍了使用SharePoint 2013中的PowerShell激活WebApplication Scoped功能(管理Web应用程序功能下的自定义支持)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 



我使用下面的脚本来激活WebApplication功能(feature1,feature2,feature3 ......等),

脚本的工作就好像所有功能都需要激活但在这里我面临的问题就像feature1处于活动状态一样,脚本没有检查第二个功能2。

ex:1)如果feature1 =已经处于活动状态 - 脚本应检查功能2并激活feature2

2)如果feature2 =已处于活动状态 - 脚本应检查feature3并激活feature3 ...等

并显示消息,因为feature1功能已激活,feature2已处于活动状态

请建议脚本如何执行,每个功能激活后的相应功能

$ ErrorActionPreference =" Stop"
cls

############################################################## #############################

$ WebApplicationScopedFeature1 =" External Feature1" #Target Web Application
$ WebApplicationScopedFeature2 =" External Feature2" #Target Web Application
$ WebApplicationScopedFeature3 =" External Feature3" #Target Web Application

############################################## ################################################ $
$ b $ args = new-object string [] 1
$ args [0] =" Cloud"

函数AddPowerShellSnapin()
{
try
{
Write-Host"添加PowerShell管理单元' -ForegroundColor Green
#尝试获取PowerShell Snappin。如果没有,那么在Catch Block上添加PowerShell snappin
Get-PSSnapin" Microsoft.SharePoint.PowerShell"
}
catch
{
if($ Error [0] .Exception.Message.Contains(" No Windows PowerShell管理单元匹配模式'Microsoft.SharePoint.PowerShell '被发现'))
{
Add-PSSnapin" Microsoft.SharePoint.PowerShell"
}
}
写主机"完成添加PowerShell管理单元" -ForegroundColor Green
}

函数ActivateFeature($ DisplayName,$ siteurl)
{
Write-Host" Activating" $ DisplayName" In Site Collection" $ siteurl
$ TempCount =(Get-SPSite $ siteurl |%{Get-SPFeature -Site $ _} | Where-Object {$ _。DisplayName -eq $ DisplayName})。Count
if($ TempCount -eq 0)
{
#如果没有,启用功能。
Get-SPFeature $ DisplayName | Enable-SPFeature -Url $ siteurl
}
else
{
#如果已经激活,则取消激活并再次激活。
Disable-SPFeature $ DisplayName -Url $ siteurl -Confirm:$ false
Get-SPFeature $ DisplayName | Enable-SPFeature -Url $ siteurl
}
}

函数ActivateFeatureInWebApplicationScope($ DisplayName,$ siteurl)
{

Write-Host "激活" $ DisplayName"在Web应用程序中" $ siteurl
$ TempCount =(Get-SPWebApplication $ siteurl |%{Get-SPFeature -WebApplication $ _} | Where-Object {$ _.DisplayName -eq $ DisplayName})。Count
if($ TempCount -eq 0)
{
#如果没有,启用功能。
Get-SPFeature $ DisplayName -WebApplication $ siteurl | Enable-SPFeature -Url $ siteurl
}
else
{
#如果已经激活,则取消激活并再次激活。
Disable-SPFeature $ DisplayName -Url $ siteurl -Confirm:$ false
Get-SPFeature $ DisplayName |启用-SPFeature -Url $ siteurl
}
}

尝试
{

AddPowerShellSnapin

#Read争论和商店环境URL
if($ args [0] -eq'Cloud')
{
#$ SiteCollectionURL =" http:// SathishServer:1001 / sites / Test"
$ WebApplicationURL =" https://qa-testportal."

}
elseif($ args [0] -eq'DEV')
{
#适当地给出URL
}
elseif ($ args [0] -eq'INT')
{
#恰当地给出URL
}

else
{
写-Host -f Yellow"未指定环境 - 请通过适当的环境进行部署(可能的值为DEV INT QA PROD)"
Log-Message $ logFilePath"未指定环境 - 请通过适当的环境进行部署(可能的值为DEV INT QA PROD)"
exit
}

ActivateFeatureInWebApplicationScope $ WebApplicationScopedFeature1 $ WebApplicationURL
ActivateFeatureInWebApplicationScope $ WebApplicationScopedFeature2 $ WebApplicationURL
ActivateFeatureInWebApplicationScope $ WebApplicationScopedFeature3 $ WebApplicationURL


写主机"脚本执行成功完成" -ForegroundColor Green
}
catch
{
Write-Host" Custom Exception Happened on Main:" + $ Error [0] .Exception.Message -ForegroundColor Red
}



解决方案

嗨Gayam,


根据我的测试,我按照您的PowerShell脚本并根据我的环境进行一些更改,Web应用程序功能都运行激活脚本:

 

ErrorActionPreference =" Stop"
cls

############################# Feature Names ###### #########################


WebApplicationScopedFeature1 =" SPSearchFeature" #Target Web Application


Hi, I am using below script to activate WebApplication features(feature1,feature2, feature3...etc) ,

the script working as if all features need to active but here i am facing issue like if feature1 is in active, the script not checking for second feature2. ex:1) if feature1=already in active--the script should check for feature 2 and activate feature2 2) if feature2=already in active--the script should check for feature3 and activate feature3 ...etc and display message as feature1 feature activated, feature2 already in active Please suggest How the script executes, the respective feature after each feature is activated $ErrorActionPreference = "Stop" cls ############################# Feature Names ############################### $WebApplicationScopedFeature1 = "External Feature1" #Target Web Application $WebApplicationScopedFeature2 = "External Feature2" #Target Web Application $WebApplicationScopedFeature3 = "External Feature3" #Target Web Application ###################################################################################### $args = new-object string[] 1 $args[0] = "Cloud" function AddPowerShellSnapin() { try { Write-Host "Adding PowerShell Snap-in" -ForegroundColor Green # Try to get the PowerShell Snappin. If not, then adding the PowerShell snappin on the Catch Block Get-PSSnapin "Microsoft.SharePoint.PowerShell" } catch { if($Error[0].Exception.Message.Contains("No Windows PowerShell snap-ins matching the pattern 'Microsoft.SharePoint.PowerShell' were found")) { Add-PSSnapin "Microsoft.SharePoint.PowerShell" } } Write-Host "Finished Adding PowerShell Snap-in" -ForegroundColor Green } function ActivateFeature($DisplayName, $siteurl) { Write-Host "Activating " $DisplayName "In Site Collection " $siteurl $TempCount = (Get-SPSite $siteurl | %{ Get-SPFeature -Site $_ } | Where-Object {$_.DisplayName -eq $DisplayName} ).Count if($TempCount -eq 0) { # if not, Enable the Feature. Get-SPFeature $DisplayName | Enable-SPFeature -Url $siteurl } else { # If already Activated, then De-Activate and Activate Again. Disable-SPFeature $DisplayName -Url $siteurl –Confirm:$false Get-SPFeature $DisplayName | Enable-SPFeature -Url $siteurl } } function ActivateFeatureInWebApplicationScope($DisplayName, $siteurl) { Write-Host "Activating " $DisplayName "In Web Application " $siteurl $TempCount = (Get-SPWebApplication $siteurl | %{ Get-SPFeature -WebApplication $_ } | Where-Object {$_.DisplayName -eq $DisplayName} ).Count if($TempCount -eq 0) { # if not, Enable the Feature. Get-SPFeature $DisplayName -WebApplication $siteurl | Enable-SPFeature -Url $siteurl } else { # If already Activated, then De-Activate and Activate Again. Disable-SPFeature $DisplayName -Url $siteurl –Confirm:$false Get-SPFeature $DisplayName | Enable-SPFeature -Url $siteurl } } try { AddPowerShellSnapin #Read arguement and store environment URL if($args[0] -eq 'Cloud') { #$SiteCollectionURL ="http://SathishServer:1001/sites/Test" $WebApplicationURL ="https://qa-testportal." } elseif($args[0] -eq 'DEV') { # Give the URLs appropriately } elseif ($args[0] -eq 'INT') { # Give the URLs appropriately } else { Write-Host -f Yellow "Environment not specified - please pass appropriate environment to deploy (Possible values are DEV INT QA PROD)" Log-Message $logFilePath "Environment not specified - please pass appropriate environment to deploy (Possible values are DEV INT QA PROD)" exit } ActivateFeatureInWebApplicationScope $WebApplicationScopedFeature1 $WebApplicationURL ActivateFeatureInWebApplicationScope $WebApplicationScopedFeature2 $WebApplicationURL ActivateFeatureInWebApplicationScope $WebApplicationScopedFeature3 $WebApplicationURL Write-Host "Script Execution Completed Successfully" -ForegroundColor Green } catch { Write-Host "Custom Exception Happened on Main : " + $Error[0].Exception.Message -ForegroundColor Red }


解决方案

Hi Gayam,

Per my test, I follow your PowerShell script and do some changes based on my environment, the web application features are all run the activate script:


ErrorActionPreference = "Stop" cls ############################# Feature Names ###############################


WebApplicationScopedFeature1 = "SPSearchFeature" #Target Web Application


这篇关于使用SharePoint 2013中的PowerShell激活WebApplication Scoped功能(管理Web应用程序功能下的自定义支持)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆